Blender  V3.3
Functions
string_utils.c File Reference
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "DNA_listBase.h"

Go to the source code of this file.

Functions

size_t BLI_split_name_num (char *left, int *nr, const char *name, const char delim)
 
bool BLI_string_is_decimal (const char *string)
 
static bool is_char_sep (const char c)
 
void BLI_string_split_suffix (const char *string, char *r_body, char *r_suf, const size_t str_len)
 
void BLI_string_split_prefix (const char *string, char *r_pre, char *r_body, const size_t str_len)
 
size_t BLI_string_flip_side_name (char *r_name, const char *from_name, const bool strip_number, const size_t name_len)
 
bool BLI_uniquename_cb (UniquenameCheckCallback unique_check, void *arg, const char *defname, char delim, char *name, size_t name_len)
 
static bool uniquename_find_dupe (ListBase *list, void *vlink, const char *name, int name_offset)
 
static bool uniquename_unique_check (void *arg, const char *name)
 
bool BLI_uniquename (ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_len)
 
Join Strings
char * BLI_string_join_array (char *result, size_t result_len, const char *strings[], uint strings_len)
 
char * BLI_string_join_array_by_sep_char (char *result, size_t result_len, char sep, const char *strings[], uint strings_len)
 
char * BLI_string_join_arrayN (const char *strings[], uint strings_len)
 
char * BLI_string_join_array_by_sep_charN (char sep, const char *strings[], uint strings_len)
 
char * BLI_string_join_array_by_sep_char_with_tableN (char sep, char *table[], const char *strings[], uint strings_len)
 

Function Documentation

◆ BLI_split_name_num()

size_t BLI_split_name_num ( char *  left,
int *  nr,
const char *  name,
char  delim 
)

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"

Parameters
leftWhere to return copy of part preceding delim.
nrWhere to return value of numeric suffix. \param name: String to split.
delimDelimiter character`.
Returns
Length of left.

Definition at line 25 of file string_utils.c.

References Freestyle::a, and left.

Referenced by BKE_main_namemap_get_name(), BKE_main_namemap_remove_name(), BKE_mball_basis_find(), BKE_mball_is_same_group(), BKE_mball_properties_copy(), BLI_uniquename_cb(), init_meta(), and main_namemap_populate().

◆ BLI_string_flip_side_name()

size_t BLI_string_flip_side_name ( char *  r_name,
const char *  from_name,
bool  strip_number,
size_t  name_len 
)

Finds the best possible flipped (left/right) name. For renaming; check for unique names afterwards.

Parameters
r_nameflipped name, assumed to be a pointer to a string of at least name_len size.
from_nameoriginal name, assumed to be a pointer to a string of at least name_len size.
strip_numberIf set, remove number extensions.
Returns
The number of bytes written into r_name.

Definition at line 112 of file string_utils.c.

References BLI_snprintf_rlen(), BLI_strcasestr(), BLI_strncpy(), BLI_strncpy_rlen(), BLI_strnlen(), is_char_sep(), len, and NULL.

Referenced by action_flip_pchan(), action_flip_pchan_rna_paths(), add_verts_to_dgroups(), armature_duplicate_selected_exec(), armature_symmetrize_exec(), BKE_object_defgroup_flip_index(), BKE_object_defgroup_flip_map(), BKE_object_defgroup_flip_map_single(), BKE_object_defgroup_mirror_selection(), BKE_pose_channel_get_mirrored(), bpy_flip_name(), ED_armature_bones_flip_names(), ED_armature_ebone_get_mirrored(), ED_wpaint_mirror_vgroup_ensure(), flip_names(), object_select_mirror_exec(), pose_bone_do_paste(), updateDuplicateCustomBoneShapes(), and updateDuplicateSubtarget().

◆ BLI_string_is_decimal()

bool BLI_string_is_decimal ( const char *  string)

Definition at line 55 of file string_utils.c.

Referenced by ED_text_is_syntax_highlight_supported(), and TEST().

◆ BLI_string_join_array()

char* BLI_string_join_array ( char *  result,
size_t  result_len,
const char *  strings[],
uint  strings_len 
)

Join strings, return newly allocated string.

Definition at line 347 of file string_utils.c.

References Freestyle::c, and result.

Referenced by draw_seq_in_view(), draw_seq_text_get_overlay_string(), and draw_viewport_name().

◆ BLI_string_join_array_by_sep_char()

char* BLI_string_join_array_by_sep_char ( char *  result,
size_t  result_len,
char  sep,
const char *  strings[],
uint  strings_len 
)

A version of BLI_string_join that takes a separator which can be any character including '\0'.

Definition at line 364 of file string_utils.c.

References Freestyle::c, and result.

Referenced by RE_render_result_full_channel_name().

◆ BLI_string_join_array_by_sep_char_with_tableN()

char* BLI_string_join_array_by_sep_char_with_tableN ( char  sep,
char *  table[],
const char *  strings[],
uint  strings_len 
)

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.

Definition at line 424 of file string_utils.c.

References BLI_strcpy_rlen(), Freestyle::c, MEM_mallocN, and result.

◆ BLI_string_join_array_by_sep_charN()

char* BLI_string_join_array_by_sep_charN ( char  sep,
const char *  strings[],
uint  strings_len 
)

A version of BLI_string_joinN that takes a separator which can be any character including '\0'.

Definition at line 400 of file string_utils.c.

References BLI_strcpy_rlen(), Freestyle::c, MEM_mallocN, and result.

◆ BLI_string_join_arrayN()

char* BLI_string_join_arrayN ( const char *  strings[],
uint  strings_len 
)

Join an array of strings into a newly allocated, null terminated string.

Definition at line 384 of file string_utils.c.

References BLI_strcpy_rlen(), Freestyle::c, MEM_mallocN, and result.

Referenced by blender::gpu::Shader::print_log(), and string_join_array_maybe_alloc().

◆ BLI_string_split_prefix()

void BLI_string_split_prefix ( const char *  string,
char *  r_pre,
char *  r_body,
size_t  str_len 
)

"a.b.c" -> ("a.", "b.c").

Definition at line 93 of file string_utils.c.

References BLI_strncpy(), BLI_strnlen(), is_char_sep(), and len.

Referenced by select_similar_prefix().

◆ BLI_string_split_suffix()

void BLI_string_split_suffix ( const char *  string,
char *  r_body,
char *  r_suf,
size_t  str_len 
)

Based on BLI_split_dirfile() / os.path.splitext(), "a.b.c" -> ("a.b", ".c").

Definition at line 75 of file string_utils.c.

References BLI_strncpy(), BLI_strnlen(), is_char_sep(), and len.

Referenced by select_similar_suffix().

◆ BLI_uniquename()

bool BLI_uniquename ( struct ListBase list,
void vlink,
const char *  defname,
char  delim,
int  name_offset,
size_t  name_len 
)

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.

Parameters
listList containing the block
vlinkThe block to check the name for
defnameTo initialize block name if latter is empty
delimDelimits numeric suffix in name
name_offsetOffset of name within block structure
name_lenMaximum length of name area

Definition at line 309 of file string_utils.c.

References BLI_assert, BLI_uniquename_cb(), data, ELEM, NULL, POINTER_OFFSET, and uniquename_unique_check().

Referenced by action_groups_add_new(), AnimationImporter::add_bone_fcurve(), add_to_modifier_list(), BKE_asset_metadata_tag_add(), BKE_constraint_unique_name(), BKE_freestyle_lineset_unique_name(), BKE_gpencil_layer_addnew(), BKE_gpencil_modifier_unique_name(), BKE_gpencil_palette_addnew(), BKE_gpencil_palettecolor_addnew(), BKE_keyblock_add(), BKE_keyingset_add(), BKE_mask_layer_unique_name(), BKE_modifier_unique_name(), BKE_nla_action_stash(), BKE_nlatrack_add(), BKE_pose_add_group(), BKE_preferences_asset_library_name_set(), BKE_scene_add_render_view(), BKE_shaderfx_unique_name(), BKE_tracking_object_unique_name(), BKE_tracking_plane_track_unique_name(), BKE_tracking_track_unique_name(), BKE_view_layer_add(), BKE_view_layer_rename(), do_versions_after_linking_300(), do_versions_nodetree_customnodes(), driver_add_new_variable(), driver_variable_unique_name(), ED_gpencil_join_objects_exec(), fcurve_add_to_list(), gpencil_layer_copy_exec(), namebutton_fn(), nodeUniqueName(), poselib_add_exec(), poselib_rename_exec(), psys_unique_name(), SEQ_modifier_unique_name(), tracks_map_merge(), viewlayer_aov_make_name_unique(), viewlayer_lightgroup_make_name_unique(), and workspace_layout_name_set().

◆ BLI_uniquename_cb()

bool BLI_uniquename_cb ( UniquenameCheckCallback  unique_check,
void arg,
const char *  defname,
char  delim,
char *  name,
size_t  name_len 
)

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.

Parameters
unique_checkReturn true if name is not unique
argAdditional arg to unique_check–meaning is up to caller
defnameTo initialize name if latter is empty
delimDelimits numeric suffix in name
nameName to be ensured unique
name_lenMaximum length of name area
Returns
true if there if the name was changed

Definition at line 233 of file string_utils.c.

References BLI_snprintf(), BLI_split_name_num(), BLI_strncpy(), BLI_strncpy_utf8_rlen(), left, and len.

Referenced by BKE_id_attribute_calc_unique_name(), BKE_nlastrip_validate_name(), BKE_object_defgroup_unique_name(), BKE_object_facemap_unique_name(), BLI_uniquename(), catalog_name_ensure_unique(), CustomData_set_layer_unique_name(), dash_segment_add_exec(), dynamicPaintSurface_setUniqueName(), ed_armature_bone_unique_name(), ED_armature_ebone_unique_name(), make_socket(), ntree_interface_identifier(), ntreeCompositOutputFileUniqueLayer(), ntreeCompositOutputFileUniquePath(), surface_setUniqueOutputName(), unique_socket_template_identifier(), and uniqueOrientationName().

◆ is_char_sep()

static bool is_char_sep ( const char  c)
static

Definition at line 70 of file string_utils.c.

References Freestyle::c, and ELEM.

Referenced by BLI_string_flip_side_name(), BLI_string_split_prefix(), and BLI_string_split_suffix().

◆ uniquename_find_dupe()

static bool uniquename_find_dupe ( ListBase list,
void vlink,
const char *  name,
int  name_offset 
)
static

Generic function to set a unique name. It is only designed to be used in situations where the name is part of the struct.

For places where this is used, see constraint.c for example...

Parameters
name_offsetshould be calculated using offsetof(structname, membername) macro from stddef.h

Definition at line 284 of file string_utils.c.

References ListBase::first, Link::next, POINTER_OFFSET, and STREQ.

Referenced by uniquename_unique_check().

◆ uniquename_unique_check()

static bool uniquename_unique_check ( void arg,
const char *  name 
)
static

Definition at line 299 of file string_utils.c.

References data, and uniquename_find_dupe().

Referenced by BLI_uniquename().