BRL-CAD
Collaboration diagram for Strings:

Files

file  str.c
 
file  escape.c
 
file  ctype.c
 

Macros

#define bu_strlcat(dst, src, size)   bu_strlcatm(dst, src, size, BU_FLSTR)
 
#define bu_strlcpy(dst, src, size)   bu_strlcpym(dst, src, size, BU_FLSTR)
 
#define bu_strdup(s)   bu_strdupm(s, BU_FLSTR)
 
#define BU_STR_EMPTY(s)   (bu_strcmp((s), "") == 0)
 
#define BU_STR_EQUAL(s1, s2)   (bu_strcmp((s1), (s2)) == 0)
 
#define BU_STR_EQUIV(s1, s2)   (bu_strcasecmp((s1), (s2)) == 0)
 

Functions

size_t bu_strlcatm (char *dst, const char *src, size_t size, const char *label)
 
size_t bu_strlcpym (char *dst, const char *src, size_t size, const char *label)
 
char * bu_strdupm (const char *cp, const char *label)
 
int bu_strcmp (const char *string1, const char *string2)
 
int bu_strncmp (const char *string1, const char *string2, size_t n)
 
int bu_strcasecmp (const char *string1, const char *string2)
 
int bu_strncasecmp (const char *string1, const char *string2, size_t n)
 
char * bu_str_escape (const char *input, const char *expression, char *output, size_t size)
 
char * bu_str_unescape (const char *input, char *output, size_t size)
 
int bu_str_isprint (const char *cp)
 
int bu_gethostname (char *hostname, size_t len)
 

Detailed Description

Macro Definition Documentation

#define bu_strlcpy (   dst,
  src,
  size 
)    bu_strlcpym(dst, src, size, BU_FLSTR)
#define bu_strdup (   s)    bu_strdupm(s, BU_FLSTR)

Definition at line 71 of file str.h.

Referenced by _ged_combadd2(), _ged_results_add(), _rt_gettree_region_end(), bu_argv_from_path(), bu_avs_add(), bu_avs_add_nonunique(), bu_backtrace(), bu_dir_list(), bu_dirname(), bu_dup_argv(), bu_dupinsert_argv(), bu_open_mapped_file(), bu_shader_to_list(), bu_str_escape(), bu_str_unescape(), build_comb(), db5_attr_create(), db5_update_ident(), db_argv_to_dpv(), db_comb_mvall(), db_dirbuild(), db_dup_subtree(), db_open(), db_open_inmem(), db_scan(), db_search(), db_string_to_path(), db_tree_parse(), db_update_ident(), diff3_dp_attr_add(), diff3_dp_attr_chgd(), diff3_dp_attr_conflict(), diff3_dp_attr_del(), diff3_dp_attr_unchgd(), diff_dp_attr_add(), diff_dp_attr_chgd(), diff_dp_attr_del(), diff_dp_attr_unchgd(), diff_init_result(), envmap_setup(), find_cmd_line_obj(), ged_bot_flip(), ged_bot_split(), ged_bot_sync(), ged_build_tops(), ged_concat(), ged_draw_guts(), ged_edcodes(), ged_editit(), ged_killtree(), ged_make(), ged_open(), ged_preview(), ged_set_output_script(), ged_track2(), ged_tree(), getRegionByName(), killtree_callback(), light_maker(), light_setup(), make_hole(), mk_addmember(), mk_extrusion(), mk_tree_gift(), mk_tree_pure(), move_all_func(), nmg_booltree_leaf_tess(), nmg_booltree_leaf_tnurb(), parse_densities_buffer(), rt_ars_adjust(), rt_comb_import4(), rt_comb_import5(), rt_do_cmd(), rt_extrude_adjust(), rt_extrude_import5(), rt_extrude_xform(), rt_pr_tree_str(), rt_sketch_adjust(), cad::gcv::obj::set_working_groupset(), cad::gcv::obj::set_working_material(), cad::gcv::obj::set_working_materiallib(), cad::gcv::obj::set_working_object(), cad::gcv::obj::set_working_shadow_obj(), cad::gcv::obj::set_working_texmap(), cad::gcv::obj::set_working_texmaplib(), cad::gcv::obj::set_working_trace_obj(), to_data_labels(), to_more_args_func(), and to_mouse_joint_selection_translate().

#define BU_STR_EMPTY (   s)    (bu_strcmp((s), "") == 0)

BU_STR_EMPTY() is a convenience macro that tests a string for emptiness, i.e. "" or NULL.

Definition at line 117 of file str.h.

#define BU_STR_EQUAL (   s1,
  s2 
)    (bu_strcmp((s1), (s2)) == 0)

BU_STR_EQUAL() is a convenience macro for testing two null-terminated strings for equality. It is equivalent to (bu_strcmp(s1, s2) == 0) whereby NULL strings are allowed and equivalent to an empty string. Evaluates true when the strings match and false if they do not.

Definition at line 126 of file str.h.

Referenced by _dl_eraseAllNamesFromDisplay(), _ged_do_list(), _ged_editit(), _ged_search_characterize_path(), _path_scrub(), _rt_getregion(), arb_mirror_face_axis(), automatic_test(), avpp_val_compare(), bn_cmd_noise(), bn_cmd_noise_slice(), bn_decode_mat(), bn_spm_load(), bn_spm_pix_load(), bn_spm_pix_save(), bn_spm_save(), brep_command(), brep_conversion_tree(), bu_avs_add(), bu_avs_get(), bu_avs_remove(), bu_brlcad_dir(), bu_cmd(), bu_cmdhist_history(), bu_dirname(), bu_file_delete(), bu_getprogname(), bu_lex(), bu_open_mapped_file(), bu_shader_to_key_eq(), bu_str_true(), bu_structparse_argv(), bu_structparse_get_terse_form(), bu_vls_struct_item_named(), bu_whereis(), bu_which(), build_comb(), check_syntax(), cho_open(), cmdhist_record(), combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), combmem_set_sca(), combmem_set_tra(), compare_bu_to_system_basename(), cyclic_path(), db5_standardize_avs(), db5_sync_attr_to_comb(), db5_sync_comb_to_attr(), db5_type_codes_from_descrip(), db5_type_codes_from_tag(), db_apply_state_from_one_member(), db_comb_mvall(), db_dircheck(), db_find_named_leaf(), db_find_named_leafs_parent(), db_lookup(), db_lookup_by_attr(), db_parse_1anim(), db_scan(), db_tree_del_dbleaf(), db_v4_get_units_code(), db_wrap_v5_external(), dimen_hook(), dl_addToDisplay(), dl_erasePathFromDisplay(), dl_set_illum(), dm_set_hook(), dm_validXType(), dmo_open_tcl(), dsk_open(), edit_str_to_arg(), f_stdattr(), file_access(), find_cmd_line_obj(), find_ref(), findjoint(), gcv_reader(), gcv_writer(), ged_adc(), ged_attr(), ged_bot_flip(), ged_bot_smooth(), ged_bot_split(), ged_bot_sync(), ged_brep(), ged_concat(), ged_dbcopy(), ged_edit(), ged_get_obj_bounds(), ged_grid(), ged_in(), ged_joint2(), ged_lod(), ged_log(), ged_make(), ged_make_name(), ged_mater(), ged_move(), ged_nirt(), ged_open(), ged_pathlist(), ged_pathsum(), ged_qray(), ged_rect(), ged_red(), ged_rt(), ged_set_uplotOutputMode(), ged_sphgroup(), ged_tables(), ged_units(), ged_view_func(), ged_which(), ged_which_shader(), get_args(), get_tcl_curve(), helpcomm(), hook_verify(), joint_selection(), light_pt_set(), main(), mlib_setup(), move_all_func(), nmg_break_all_es_on_v(), noise_setup(), observer_attach(), observer_detach(), osl_parse(), osl_parse_shader(), parse_struct_lookup(), rt_arbn_adjust(), rt_arbn_get(), rt_ars_adjust(), rt_ars_get(), rt_binunif_adjust(), rt_binunif_get(), rt_bot_adjust(), rt_bot_get(), rt_comb_adjust(), rt_comb_get(), rt_ebm_adjust(), rt_ebm_get(), rt_extrude_adjust(), rt_extrude_get(), rt_id_solid(), rt_nmg_adjust(), rt_nmg_get(), rt_nurb_adjust(), rt_regionfix(), rt_sketch_adjust(), rt_sketch_get(), rt_submodel_prep(), rt_tcl_rt(), run_server(), select_filter(), sh_stk_dosetup(), str2type(), stxt_transp_hook(), tcl_bu_get_value_by_keyword(), test_encode(), test_vls(), to_autoview(), to_axes(), to_bg(), to_bounds(), to_cmd(), to_configure(), to_constrain_rmode(), to_constrain_tmode(), to_copy(), to_data_arrows(), to_data_axes(), to_data_labels(), to_data_lines(), to_data_move(), to_data_move_object_mode(), to_data_move_point_mode(), to_data_pick(), to_data_polygons(), to_data_scale(), to_data_scale_mode(), to_data_vZ(), to_delete_view(), to_dm_func(), to_edit_motion_delta_callback(), to_faceplate(), to_fontsize(), to_get_prev_mouse(), to_handle_refresh(), to_hide_view(), to_idle_mode(), to_init_view_bindings(), to_light(), to_listen(), to_model_axes(), to_mouse_append_pt_common(), to_mouse_brep_selection_append(), to_mouse_brep_selection_translate(), to_mouse_constrain_rot(), to_mouse_constrain_trans(), to_mouse_find_arb_edge(), to_mouse_find_bot_edge(), to_mouse_find_botpt(), to_mouse_find_metaballpt(), to_mouse_find_pipept(), to_mouse_joint_select(), to_mouse_joint_selection_translate(), to_mouse_move_arb_edge(), to_mouse_move_arb_face(), to_mouse_move_botpt(), to_mouse_move_botpts(), to_mouse_move_pt_common(), to_mouse_orotate(), to_mouse_oscale(), to_mouse_otranslate(), to_mouse_poly_circ(), to_mouse_poly_cont(), to_mouse_poly_ell(), to_mouse_poly_rect(), to_mouse_protate(), to_mouse_pscale(), to_mouse_ptranslate(), to_mouse_rect(), to_mouse_rot(), to_mouse_rotate_arb_face(), to_mouse_trans(), to_move_arb_edge_mode(), to_move_arb_face_mode(), to_move_botpt_mode(), to_move_botpts_mode(), to_move_metaballpt_mode(), to_move_pipept_mode(), to_new_view(), to_open_tcl(), to_orotate_mode(), to_oscale_mode(), to_otranslate_mode(), to_paint_rect_area(), to_poly_circ_mode(), to_poly_cont_build(), to_poly_cont_build_end(), to_poly_ell_mode(), to_poly_rect_mode(), to_protate_mode(), to_pscale_mode(), to_ptranslate_mode(), to_rect_mode(), to_rotate_arb_face_mode(), to_rotate_mode(), to_rt_gettrees_application(), to_scale_mode(), to_screen2model(), to_screen2view(), to_set_coord(), to_set_fb_mode(), to_snap_view(), to_translate_mode(), to_transparency(), to_view2screen(), to_view_axes(), to_view_callback(), to_view_func_common(), to_view_win_size(), to_vmake(), to_vslew(), to_zbuffer(), to_zclip(), translate_command(), txt_setup(), txt_transp_hook(), and verbIn().

#define BU_STR_EQUIV (   s1,
  s2 
)    (bu_strcasecmp((s1), (s2)) == 0)

BU_STR_EQUIV() is a convenience macro that compares two null-terminated strings for equality without regard for case. Two strings are equivalent if they are a case-insensitive match. NULL strings are allowed and equivalent to an empty string. Evaluates true if the strings are similar and false if they are not.

Definition at line 135 of file str.h.

Referenced by attr_cmd(), db5_is_standard_attribute(), db5_standardize_attribute(), fbo_flush_tcl(), fbo_getcursor_tcl(), fbo_getheight_tcl(), fbo_getsize_tcl(), fbo_getwidth_tcl(), ged_attr(), and ged_constraint().

Function Documentation

size_t bu_strlcatm ( char *  dst,
const char *  src,
size_t  size,
const char *  label 
)

concatenate one string onto the end of another, returning the length of the dst string after the concatenation.

bu_strlcat() is a macro to bu_strlcatm() so that we can report the file name and line number of any erroneous callers.

Definition at line 40 of file str.c.

References bu_debug, BU_SEM_SYSCALL, bu_semaphore_acquire(), bu_semaphore_release(), and UNLIKELY.

Here is the call graph for this function:

size_t bu_strlcpym ( char *  dst,
const char *  src,
size_t  size,
const char *  label 
)

copies one string into another, returning the length of the dst string after the copy.

bu_strlcpy() is a macro to bu_strlcpym() so that we can report the file name and line number of any erroneous callers.

Definition at line 96 of file str.c.

References bu_debug, BU_SEM_SYSCALL, bu_semaphore_acquire(), bu_semaphore_release(), and UNLIKELY.

Here is the call graph for this function:

char* bu_strdupm ( const char *  cp,
const char *  label 
)

Given a string, allocate enough memory to hold it using bu_malloc(), duplicate the strings, returns a pointer to the new string.

bu_strdup() is a macro that includes the current file name and line number that can be used when bu debugging is enabled.

int bu_strcmp ( const char *  string1,
const char *  string2 
)

Compares two strings for equality. It performs the comparison more robustly than the standard library's strcmp() function by defining consistent behavior for NULL and empty strings. It accepts NULL as valid input values and considers "" and NULL as equal. Returns 0 if the strings match.

Definition at line 171 of file str.c.

Referenced by _ged_cmp_attr(), add_unique_pair(), attr_cmp(), attr_cmp_value(), automatic_test(), avs_check(), bu_vls_strcmp(), cmpdirname(), comp_3(), edcodes_reg_compare(), ged_lc(), getRegionByName(), main(), name_compare(), and typecompare().

int bu_strncmp ( const char *  string1,
const char *  string2,
size_t  n 
)

Compares two strings for equality. No more than n-characters are compared. It performs the comparison more robustly than the standard library's strncmp() function by defining consistent behavior for NULL and empty strings. It accepts NULL as valid input values and considers "" and NULL as equal. Returns 0 if the strings match.

Definition at line 191 of file str.c.

Referenced by arb_permute(), backtrace(), bu_avail_cpus(), bu_vls_strncmp(), compare_result(), fb_open(), fb_set_interface(), ged_bot(), ged_get_obj_bounds(), ged_in(), ged_keep(), ged_loadframe(), ged_loadview(), ged_mater(), ged_nmg_simplify(), ged_saveview(), img_source_hook(), main(), mem_open(), nmg_2_vrml(), qt_open(), read_units_double(), rt_bot_adjust(), rt_bot_get(), rt_bot_propget(), rt_do_cmd(), rt_get_functab_by_label(), rt_metaball_lookup_type_id(), stk_open(), toyota_setup(), txt_source_hook(), and wdb_importFg4Section_cmd().

int bu_strcasecmp ( const char *  string1,
const char *  string2 
)

Compares two strings for equality without regard for the case in the string. It performs the comparison more robustly than the standard strcasecmp()/stricmp() function by defining consistent behavior for NULL and empty strings. It accepts NULL as valid input values and considers "" and NULL as equal. Returns 0 if the strings match.

Definition at line 211 of file str.c.

Referenced by attr_cmp_nocase(), attr_cmp_value_nocase(), gcv_extension_match(), and main().

int bu_strncasecmp ( const char *  string1,
const char *  string2,
size_t  n 
)

Compares two strings for equality without regard for the case in the string. No more than n-characters are compared. It performs the comparison more robustly than the standard strncasecmp()/strnicmp() function by defining consistent behavior for NULL and empty strings. It accepts NULL as valid input values and considers "" and NULL as equal. Returns 0 if the strings match.

Definition at line 239 of file str.c.

Referenced by bu_shader_to_list(), gcv_extension_match(), main(), and rt_dspline_matrix().

char* bu_str_escape ( const char *  input,
const char *  expression,
char *  output,
size_t  size 
)

Escapes an input string with preceding '\'s for any characters defined in the 'expression' string. The input string is written to the specified output buffer of 'size' capacity. The input and output pointers may overlap or be the same memory (assuming adequate space is available). If 'output' is NULL, then dynamic memory will be allocated and returned.

The 'expression' parameter is a regular "bracket expression" commonly used in globbing and POSIX regular expression character matching. An expression can be either a matching list (default) or a non-matching list (starting with a circumflex '^' character). For example, "abc" matches any of the characters 'a', 'b', or 'c'. Specifying a non-matching list expression matches any character except for the ones listed after the circumflex. For example, "^abc" matches any character except 'a', 'b', or 'c'.

Backslash escape sequences are not allowed (e.g., \t or \x01) as '\' will be matched literally.

A range expression consists of two characters separated by a hyphen and will match any single character between the two characters. For example, "0-9a-c" is equivalent to "0123456789abc". To match a '-' dash literally, include it as the last or first (after any '^') character within the expression.

The expression may also contain named character classes but only for ASCII input strings:

[:alnum:] Alphanumeric characters: a-zA-Z0-9 [:alpha:] Alphabetic characters: a-zA-Z [:blank:] Space and TAB characters [:cntrl:] Control characters: ACSII 0x00-0X7F [:digit:] Numeric characters: 0-9 [:graph:] Characters that are both printable and visible: ASCII 0x21-0X7E [:lower:] Lowercase alphabetic characters: a-z [:print:] Visible and space characters (not control characters): ASCII 0x20-0X7E [:punct:] Punctuation characters (not letters, digits, control, or space): ][!"#$%&'()*+,./:;<=>?@^_`{|}~-\ [:upper:] Uppercase alphabetic characters: A-Z [:xdigit:] Hexadecimal digits: a-fA-F0-9 [:word:] (non-POSIX) Alphanumeric plus underscore: a-zA-Z0-9_

A non-NULL output string is always returned. This allows expression chaining and embedding as function arguments but care should be taken to free the dynamic memory being returned when 'output' is NULL.

If output 'size' is inadequate for holding the escaped input string, bu_bomb() is called.

Example: char *result; char buf[128]; result = bu_str_escape("my fair lady", " ", buf, 128); :: result == buf == "my\ fair\ lady" result = bu_str_escape(buf, "\", NULL, 0); :: result == "my\\ fair\\ lady" :: buf == "my\ fair\ lady" bu_free(result, "bu_str_escape"); result = bu_str_escape(buf, "a-zA-Z", buf, 128); :: result == buf == "\m\y\ \f\a\i\r\ \l\a\d\y"

This function should be thread safe and re-entrant if the input/output buffers are not shared (and strlen() is threadsafe).

Definition at line 53 of file escape.c.

References bu_bomb(), bu_calloc(), bu_free(), bu_strdup, BU_VLS_INIT_ZERO, bu_vls_strgrab(), and UNLIKELY.

Referenced by main().

Here is the call graph for this function:

char* bu_str_unescape ( const char *  input,
char *  output,
size_t  size 
)

Removes one level of '\' escapes from an input string. The input string is written to the specified output buffer of 'size' capacity. The input and output pointers may overlap or be the same memory. If 'output' is NULL, then dynamic memory will be allocated and returned.

A non-NULL output string is always returned. This allows expression chaining and embedding as function arguments but care should be taken to free the dynamic memory being returned when 'output' is NULL.

If output 'size' is inadequate for holding the unescaped input string, bu_bomb() is called.

Example: char *result; char buf[128]; result = bu_str_unescape("\m\y\\ \f\a\i\r\\ \l\a\d\y", buf, 128); :: result == buf == "my\ fair\ lady" result = bu_str_unescape(buf, NULL, 0); :: result == "my fair lady" :: buf == "my\ fair\ lady" bu_free(result, "bu_str_unescape");

This function should be thread safe and re-entrant if the input/output buffers are not shared (and strlen() is threadsafe).

Definition at line 149 of file escape.c.

References bu_bomb(), bu_calloc(), bu_free(), bu_strdup, and UNLIKELY.

Referenced by main().

Here is the call graph for this function:

int bu_str_isprint ( const char *  cp)

Definition at line 28 of file ctype.c.

Referenced by test_str_isprint().

int bu_gethostname ( char *  hostname,
size_t  len 
)

Get the current operating host's name. This is usually also the network name of the current host. The name is written into the provided hostname buffer of at least len size. The hostname is always null-terminated and should be sized accordingly.

Definition at line 30 of file gethostname.c.

References bu_log(), and bu_strlcpy.

Referenced by main().

Here is the call graph for this function: