# strings_func.h File Reference

Functions related to OTTD's strings. More...

`#include "strings_type.h"`

Go to the source code of this file.

## Data Structures

struct | StringIDCompare
| Key comparison function for std::map. More...

## Functions

char * | InlineString (char *buf, StringID string)
char * | GetString (char *buffr, StringID string, const char *last)
const char * | GetStringPtr (StringID string)
void | InjectDParam (int amount)
static void | SetDParamX (uint64 *s, uint n, uint64 v)
static void | SetDParam (uint n, uint64 v)
void | SetDParamStr (uint n, const char *str)
| This function is used to "bind" a C string to a OpenTTD dparam slot.
StringID | BindCString (const char *str)
| This function takes a C-string and allocates a temporary string ID.
static uint64 | GetDParamX (const uint64 *s, uint n)
static uint64 | GetDParam (uint n)
static void | CopyInDParam (int offs, const uint64 *src, int num)
static void | CopyOutDParam (uint64 *dst, int offs, int num)
bool | ReadLanguagePack (int index)
void | InitializeLanguagePacks ()
| Make a list of the available language packs.
int CDECL | StringIDSorter (const void *a, const void *b)
void | CheckForMissingGlyphsInLoadedLanguagePack ()
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

## Variables

char | _userstring [128]
DynamicLanguages | _dynlang

## Detailed Description

Functions related to OTTD's strings.

Definition in file strings_func.h.

## Function Documentation

StringID BindCString | ( | const char * | str | ) |

This function takes a C-string and allocates a temporary string ID.

The duration of the bound string is valid only until the next call to GetString, so be careful.

The StringID of the bound string is valid until BindCString is called another NUM_BOUND_STRINGS times. So be careful when using it.

Parameters:

  | str | temp string to add

Returns:
  the id of that temp string

Note:
  formatting a DATE_TINY calls BindCString twice, thus reduces the amount of 'user' bound strings by 2.

Todo:
  rewrite the BindCString system to make the limit flexible and non-round-robin. For example by using smart pointers that free the allocated StringID when they go out-of-scope/are freed.

Definition at line 212 of file strings.cpp.

Referenced by CheckForMissingGlyphsInLoadedLanguagePack(), and SetDParamStr().

void CheckForMissingGlyphsInLoadedLanguagePack | ( |  | ) |

Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

If this is the case an error message will be shown in English. The error message will not be localized because that would mean it might use characters that are not in the font, which is the whole reason this check has been added.

Definition at line 1494 of file strings.cpp.

References BindCString().

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

put the data in _dynlang struct.

< Matching the language in the configuartion file or the current locale

< Using pt_PT for pt_BR locale when pt_BR is not available

< Fallback when no locale-matching language has been found

Definition at line 1426 of file strings.cpp.

References DynamicLanguages::curr_file, DynamicLanguages::ent, error, Language::file, FOR_ALL_SEARCHPATHS, GetCurrentLocale(), GetLanguageFileHeader(), GetLanguageList(), LANG_DIR, Language::name, and DynamicLanguages::num.

void SetDParamStr | ( | uint | n,
|  | const char * | str |
| ) |  |  |

This function is used to "bind" a C string to a OpenTTD dparam slot.

Parameters:

  | n | slot of the string
  | str | string to bind

Definition at line 223 of file strings.cpp.

References BindCString().

Referenced by GetSaveLoadErrorString(), RailVehicleLengthChanged(), SaveFileError(), and StartScenario().