| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2017 by the Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bli | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdarg.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 18:16:39 +02:00
										 |  |  | #include "BLI_compiler_attrs.h"
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ListBase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef bool (*UniquenameCheckCallback)(void *arg, const char *name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Looks for a numeric suffix preceded by `delim` character on the end of | 
					
						
							|  |  |  |  * name, puts preceding part into *left and value of suffix into *nr. | 
					
						
							|  |  |  |  * Returns the length of *left. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Foo.001 -> "Foo", 1 | 
					
						
							|  |  |  |  * Returning the length of "Foo" | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param left: Where to return copy of part preceding `delim`. | 
					
						
							|  |  |  |  * \param nr: Where to return value of numeric suffix`. | 
					
						
							|  |  |  |  * \param name: String to split`. | 
					
						
							|  |  |  |  * \param delim: Delimiter character`. | 
					
						
							|  |  |  |  * \return Length of \a left. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-01-07 11:38:08 +11:00
										 |  |  | size_t BLI_split_name_num(char *left, int *nr, const char *name, char delim); | 
					
						
							| 
									
										
										
										
											2019-08-13 15:35:48 +02:00
										 |  |  | bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Based on `BLI_split_dirfile()` / `os.path.splitext()`, | 
					
						
							|  |  |  |  * `"a.b.c"` -> (`"a.b"`, `".c"`). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-01-12 11:42:54 +11:00
										 |  |  | void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * `"a.b.c"` -> (`"a."`, `"b.c"`). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-01-12 11:42:54 +11:00
										 |  |  | void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); | 
					
						
							| 
									
										
										
										
											2017-01-16 20:34:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Join strings, return newly allocated string. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-10 01:23:43 +11:00
										 |  |  | char *BLI_string_join_array(char *result, | 
					
						
							|  |  |  |                             size_t result_len, | 
					
						
							|  |  |  |                             const char *strings[], | 
					
						
							|  |  |  |                             uint strings_len) ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A version of #BLI_string_join that takes a separator which can be any character including '\0'. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-04 15:12:06 +11:00
										 |  |  | char *BLI_string_join_array_by_sep_char(char *result, | 
					
						
							|  |  |  |                                         size_t result_len, | 
					
						
							|  |  |  |                                         char sep, | 
					
						
							|  |  |  |                                         const char *strings[], | 
					
						
							|  |  |  |                                         uint strings_len) ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2020-02-10 01:23:43 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Join an array of strings into a newly allocated, null terminated string. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | char *BLI_string_join_arrayN(const char *strings[], uint strings_len) ATTR_WARN_UNUSED_RESULT | 
					
						
							|  |  |  |     ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A version of #BLI_string_joinN that takes a separator which can be any character including '\0'. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | char *BLI_string_join_array_by_sep_charN(char sep, | 
					
						
							|  |  |  |                                          const char *strings[], | 
					
						
							|  |  |  |                                          uint strings_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A version of #BLI_string_join_array_by_sep_charN that takes a table array. | 
					
						
							|  |  |  |  * The new location of each string is written into this array. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | char *BLI_string_join_array_by_sep_char_with_tableN(char sep, | 
					
						
							|  |  |  |                                                     char *table[], | 
					
						
							|  |  |  |                                                     const char *strings[], | 
					
						
							|  |  |  |                                                     uint strings_len) ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Take multiple arguments, pass as (array, length). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-10 01:23:43 +11:00
										 |  |  | #define BLI_string_join(result, result_len, ...) \
 | 
					
						
							|  |  |  |   BLI_string_join_array( \ | 
					
						
							|  |  |  |       result, result_len, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | #define BLI_string_joinN(...) \
 | 
					
						
							| 
									
										
										
										
											2017-08-23 20:04:26 +10:00
										 |  |  |   BLI_string_join_arrayN(((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | #define BLI_string_join_by_sep_charN(sep, ...) \
 | 
					
						
							|  |  |  |   BLI_string_join_array_by_sep_charN( \ | 
					
						
							| 
									
										
										
										
											2017-08-23 20:04:26 +10:00
										 |  |  |       sep, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | #define BLI_string_join_by_sep_char_with_tableN(sep, table, ...) \
 | 
					
						
							|  |  |  |   BLI_string_join_array_by_sep_char_with_tableN( \ | 
					
						
							| 
									
										
										
										
											2017-08-23 20:04:26 +10:00
										 |  |  |       sep, table, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__)) | 
					
						
							| 
									
										
										
										
											2017-08-23 18:16:46 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Finds the best possible flipped (left/right) name. | 
					
						
							|  |  |  |  * For renaming; check for unique names afterwards. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param r_name: flipped name, | 
					
						
							|  |  |  |  * assumed to be a pointer to a string of at least \a name_len size. | 
					
						
							|  |  |  |  * \param from_name: original name, | 
					
						
							|  |  |  |  * assumed to be a pointer to a string of at least \a name_len size. | 
					
						
							|  |  |  |  * \param strip_number: If set, remove number extensions. | 
					
						
							|  |  |  |  * \return The number of bytes written into \a r_name. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-09-01 15:24:01 +10:00
										 |  |  | size_t BLI_string_flip_side_name(char *r_name, | 
					
						
							|  |  |  |                                  const char *from_name, | 
					
						
							| 
									
										
										
										
											2022-01-07 11:38:08 +11:00
										 |  |  |                                  bool strip_number, | 
					
						
							| 
									
										
										
										
											2022-01-12 11:42:54 +11:00
										 |  |  |                                  size_t name_len); | 
					
						
							| 
									
										
										
										
											2017-01-16 20:34:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Ensures name is unique (according to criteria specified by caller in unique_check callback), | 
					
						
							|  |  |  |  * incrementing its numeric suffix as necessary. Returns true if name had to be adjusted. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param unique_check: Return true if name is not unique | 
					
						
							|  |  |  |  * \param arg: Additional arg to unique_check--meaning is up to caller | 
					
						
							|  |  |  |  * \param defname: To initialize name if latter is empty | 
					
						
							|  |  |  |  * \param delim: Delimits numeric suffix in name | 
					
						
							|  |  |  |  * \param name: Name to be ensured unique | 
					
						
							|  |  |  |  * \param name_len: Maximum length of name area | 
					
						
							|  |  |  |  * \return true if there if the name was changed | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | bool BLI_uniquename_cb(UniquenameCheckCallback unique_check, | 
					
						
							|  |  |  |                        void *arg, | 
					
						
							|  |  |  |                        const char *defname, | 
					
						
							|  |  |  |                        char delim, | 
					
						
							|  |  |  |                        char *name, | 
					
						
							|  |  |  |                        size_t name_len); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:44 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Ensures that the specified block has a unique name within the containing list, | 
					
						
							|  |  |  |  * incrementing its numeric suffix as necessary. Returns true if name had to be adjusted. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param list: List containing the block | 
					
						
							|  |  |  |  * \param vlink: The block to check the name for | 
					
						
							|  |  |  |  * \param defname: To initialize block name if latter is empty | 
					
						
							|  |  |  |  * \param delim: Delimits numeric suffix in name | 
					
						
							|  |  |  |  * \param name_offset: Offset of name within block structure | 
					
						
							|  |  |  |  * \param name_len: Maximum length of name area | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | bool BLI_uniquename(struct ListBase *list, | 
					
						
							|  |  |  |                     void *vlink, | 
					
						
							|  |  |  |                     const char *defname, | 
					
						
							|  |  |  |                     char delim, | 
					
						
							| 
									
										
										
										
											2021-03-08 14:44:57 +11:00
										 |  |  |                     int name_offset, | 
					
						
							| 
									
										
										
										
											2021-12-14 18:35:23 +11:00
										 |  |  |                     size_t name_len); | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |