Freeciv-3.1: /fast/freeciv/nightly/S3_1/utility/string_vector.c File Reference

Freeciv-3.1

Loading...
Searching...
No Matches
Data Structures | Functions
string_vector.c File Reference
`#include <stdlib.h>`
`#include <string.h>`
`#include "astring.h"`
`#include "mem.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "string_vector.h"`

Go to the source code of this file.

## Data Structures

struct | strvec

## Functions

static void | string_free (char *string)
static char * | string_duplicate (const char *string)
struct strvec * | strvec_new (void)
void | strvec_destroy (struct strvec *psv)
void | strvec_reserve (struct strvec *psv, size_t reserve)
void | strvec_store (struct strvec *psv, const char *const *vec, size_t size)
void | strvec_from_str (struct strvec *psv, char separator, const char *str)
void | strvec_clear (struct strvec *psv)
void | strvec_remove_duplicate (struct strvec *psv, int(*cmp_func)(const char *, const char *))
void | strvec_remove_empty (struct strvec *psv)
void | strvec_copy (struct strvec *dest, const struct strvec *src)
void | strvec_sort (struct strvec *psv, int(*sort_func)(const char *const *, const char *const *))
void | strvec_prepend (struct strvec *psv, const char *string)
void | strvec_append (struct strvec *psv, const char *string)
void | strvec_insert (struct strvec *psv, size_t svindex, const char *string)
bool | strvec_set (struct strvec *psv, size_t svindex, const char *string)
bool | strvec_remove (struct strvec *psv, size_t svindex)
size_t | strvec_size (const struct strvec *psv)
bool | are_strvecs_equal (const struct strvec *stv1, const struct strvec *stv2)
const char *const * | strvec_data (const struct strvec *psv)
bool | strvec_index_valid (const struct strvec *psv, size_t svindex)
const char * | strvec_get (const struct strvec *psv, size_t svindex)
void | strvec_to_str (const struct strvec *psv, char separator, char *buf, size_t buf_len)
const char * | strvec_to_or_list (const struct strvec *psv, struct astring *astr)
const char * | strvec_to_and_list (const struct strvec *psv, struct astring *astr)

## Function Documentation

## ◆ are_strvecs_equal()

bool are_strvecs_equal | ( | const struct strvec * | stv1,
|  | const struct strvec * | stv2
| ) |  |

Returns TRUE if stv1 and stv2 are equal.

Definition at line 351 of file string_vector.c.

## ◆ string_duplicate()

static char * string_duplicate | ( | const char * | string | ) |

static

Duplicate a string.

Definition at line 47 of file string_vector.c.

Referenced by strvec_append(), strvec_copy(), strvec_insert(), strvec_prepend(), and strvec_set().

## ◆ string_free()

static void string_free | ( | char * | string | ) |

static

Free a string.

Definition at line 37 of file string_vector.c.

Referenced by strvec_clear(), strvec_copy(), strvec_remove(), strvec_reserve(), and strvec_set().

## ◆ strvec_append()

void strvec_append | ( | struct strvec * | psv,
|  | const char * | string
| ) |  |

Insert a string at the end of the vector.

Definition at line 278 of file string_vector.c.

Referenced by base_get_dirs(), fileinfolist(), get_effect_list_req_text(), get_themes_list(), get_tileset_list(), helptext_government(), helptext_unit(), insert_allows_single(), luascript_func_check(), mapimg_get_format_list(), values_dlg::open_help(), setting_bitwise_to_str(), strvec_from_str(), strvec_insert(), strvec_store(), and video_mode_list().

## ◆ strvec_clear()

void strvec_clear | ( | struct strvec * | psv | ) |

Remove all strings from the vector.

Definition at line 159 of file string_vector.c.

Referenced by helptext_unit(), strvec_copy(), strvec_destroy(), strvec_from_str(), strvec_remove(), strvec_reserve(), and strvec_store().

## ◆ strvec_copy()

void strvec_copy | ( | struct strvec * | dest,
|  | const struct strvec * | src
| ) |  |

Copy a string vector.

Definition at line 237 of file string_vector.c.

## ◆ strvec_data()

const char *const * strvec_data | ( | const struct strvec * | psv | ) |

Returns the datas of the vector.

Definition at line 372 of file string_vector.c.

## ◆ strvec_destroy()

void strvec_destroy | ( | struct strvec * | psv | ) |

Destroy a string vector.

Definition at line 71 of file string_vector.c.

Referenced by enum_widget_destroy(), extras_free(), free_data_dir_names(), get_effect_list_req_text(), get_theme_list(), get_tileset_list(), goods_free(), government_free(), helptext_government(), helptext_unit(), improvement_free(), insert_allows_single(), multipliers_free(), researches_free(), send_ruleset_choices(), server_option_free(), setting_bitwise_to_str(), show_rulesets(), specialists_free(), tech_free(), terrains_free(), themespec_try_read(), tilespec_try_read(), unit_classes_free(), unit_type_free(), and video_mode_widget_destroy().

## ◆ strvec_from_str()

void strvec_from_str | ( | struct strvec * | psv,
|  | char | separator,
|  | const char * | str
| ) |  |

Build the string vector from a string until 'str_size' bytes are read. Passing -1 for 'str_size' will assume 'str' as the expected format. Note it's a bit dangerous.

This string format is a list of strings separated by 'separator'.

See also strvec_to_str().

Definition at line 136 of file string_vector.c.

## ◆ strvec_get()

const char * strvec_get | ( | const struct strvec * | psv,
|  | size_t | svindex
| ) |  |

Returns the string at the index of the vector.

Definition at line 388 of file string_vector.c.

Referenced by option_dialog::add_option(), client_option_bitwise_secfile_str(), client_option_enum_secfile_str(), get_themes_list(), option_dialog_option_add(), option_enum_def_str(), option_enum_get_str(), option_enum_int_to_str(), option_enum_str_to_int(), option_widget_apply(), option_widget_new(), research_advance_name_translation(), research_advance_rule_name(), research_future_set_name(), save_strvec(), server_option_enum_set(), and server_option_enum_support_name().

## ◆ strvec_index_valid()

bool strvec_index_valid | ( | const struct strvec * | psv,
|  | size_t | svindex
| ) |  |

Returns TRUE if the index is valid.

Definition at line 380 of file string_vector.c.

Referenced by strvec_get(), strvec_remove(), and strvec_set().

## ◆ strvec_insert()

void strvec_insert | ( | struct strvec * | psv,
|  | size_t | svindex,
|  | const char * | string
| ) |  |

Insert a string at the index of the vector.

Definition at line 287 of file string_vector.c.

## ◆ strvec_new()

struct strvec * strvec_new | ( | void |  | ) |

Create a new string vector.

Definition at line 58 of file string_vector.c.

Referenced by base_get_dirs(), fileinfolist(), get_effect_list_req_text(), get_soundplugin_list(), get_themes_list(), get_tileset_list(), helptext_government(), helptext_unit(), insert_allows_single(), lookup_strvec(), mapimg_get_format_list(), values_dlg::open_help(), option_widget_new(), researches_init(), setting_bitwise_to_str(), and video_mode_list().

## ◆ strvec_prepend()

void strvec_prepend | ( | struct strvec * | psv,
|  | const char * | string
| ) |  |

Insert a string at the start of the vector.

Definition at line 268 of file string_vector.c.

Referenced by strvec_insert().

## ◆ strvec_remove()

bool strvec_remove | ( | struct strvec * | psv,
|  | size_t | svindex
| ) |  |

Remove the string at the index from the vector. Returns TRUE if the element has been really removed.

Definition at line 319 of file string_vector.c.

Referenced by strvec_remove_duplicate(), and strvec_remove_empty().

## ◆ strvec_remove_duplicate()

void strvec_remove_duplicate | ( | struct strvec * | psv,
|  | int(*)(const char *, const char *) | cmp_func
| ) |  |

Remove strings which are duplicated inside the vector.

Definition at line 179 of file string_vector.c.

Referenced by fileinfolist(), get_data_dirs(), get_save_dirs(), and get_scenario_dirs().

## ◆ strvec_remove_empty()

void strvec_remove_empty | ( | struct strvec * | psv | ) |

Remove all empty strings from the vector and removes all leading and trailing spaces.

Definition at line 207 of file string_vector.c.

Referenced by helpeditor::close().

## ◆ strvec_reserve()

void strvec_reserve | ( | struct strvec * | psv,
|  | size_t | reserve
| ) |  |

Set the size of the vector.

Definition at line 80 of file string_vector.c.

Referenced by get_soundplugin_list(), option_widget_new(), research_future_set_name(), strvec_append(), strvec_copy(), strvec_insert(), strvec_prepend(), strvec_remove(), and strvec_store().

## ◆ strvec_set()

bool strvec_set | ( | struct strvec * | psv,
|  | size_t | svindex,
|  | const char * | string
| ) |  |

Replace a string at the index of the vector. Returns TRUE if the element has been really set.

Definition at line 305 of file string_vector.c.

Referenced by helpeditor::close(), get_soundplugin_list(), option_widget_new(), research_future_set_name(), and strvec_store().

## ◆ strvec_size()

size_t strvec_size | ( | const struct strvec * | psv | ) |

Returns the size of the vector.

Definition at line 343 of file string_vector.c.

Referenced by option_dialog::add_option(), are_strvecs_equal(), client_option_bitwise_secfile_str(), client_option_enum_secfile_str(), client_option_enum_set(), helpeditor::close(), combo_popup(), get_gui_specific_themes_directories(), get_theme_list(), get_themes_list(), helpeditor::helpeditor(), helptext_government(), helptext_unit(), insert_allows_single(), values_dlg::open_help(), option_bitwise_mask(), option_dialog_option_add(), option_enum_str_to_int(), option_widget_apply(), option_widget_new(), qtg_get_gui_specific_themes_directories(), research_future_set_name(), save_strvec(), and setting_bitwise_to_str().

## ◆ strvec_sort()

void strvec_sort | ( | struct strvec * | psv,
|  | int(*)(const char *const *, const char *const *) | sort_func
| ) |  |

Sort the string vector, using qsort().

Definition at line 258 of file string_vector.c.

Referenced by fileinfolist().

## ◆ strvec_store()

void strvec_store | ( | struct strvec * | psv,
|  | const char *const * | vec,
|  | size_t | size
| ) |  |

Stores the string vector from a normal vector. If size == -1, it will assume it is a NULL terminated vector.

Definition at line 110 of file string_vector.c.

Referenced by lookup_strvec().

## ◆ strvec_to_and_list()

const char * strvec_to_and_list | ( | const struct strvec * | psv,
|  | struct astring * | astr
| ) |  |

Build a localized string with the elements of the string vector. Elements will be "and"-separated.

See also astr_build_and_list(), strvec_to_or_list().

Definition at line 441 of file string_vector.c.

Referenced by get_effect_list_req_text(), helptext_government(), helptext_unit(), insert_allows_single(), and setting_bitwise_to_str().

## ◆ strvec_to_or_list()

const char * strvec_to_or_list | ( | const struct strvec * | psv,
|  | struct astring * | astr
| ) |  |

Build a localized string with the elements of the string vector. Elements will be "or"-separated.

See also astr_build_or_list(), strvec_to_and_list().

Definition at line 428 of file string_vector.c.

Referenced by helptext_government(), and insert_allows_single().

## ◆ strvec_to_str()

void strvec_to_str | ( | const struct strvec * | psv,
|  | char | separator,
|  | char * | buf,
|  | size_t | buf_len
| ) |  |

Build the string from a string vector.

This string format is a list of strings separated by 'separator'.

See also strvec_from_str().

Definition at line 400 of file string_vector.c.