string_func.h File Reference

Functions related to low-level strings. More...

#include "core/bitmath_func.hpp"
#include "string_type.h"

Go to the source code of this file.

Functions

void ttd_strlcat (char *dst, const char *src, size_t size)
 usage ttd_strlcpy(dst, src, lengthof(dst));
void ttd_strlcpy (char *dst, const char *src, size_t size)
char * strecat (char *dst, const char *src, const char *last)
 usage: strecpy(dst, src, lastof(dst));
char * strecpy (char *dst, const char *src, const char *last)
char *CDECL str_fmt (const char *str,...)
void str_validate (char *str)
 Scans the string for valid characters and if it finds invalid ones, replaces them with a question mark '?'.
void str_strip_colours (char *str)
 Scans the string for colour codes and strips them.
void strtolower (char *str)
 Convert the given string to lowercase, only works with ASCII!
static bool StrEmpty (const char *s)
static int ttd_strnlen (const char *str, int maxlen)
 Get the length of a string, within a limited buffer.
char * md5sumToString (char *buf, const char *last, const uint8 md5sum[16])
 Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer.
bool IsValidChar (WChar key, CharSetFilter afilter)
 Only allow certain keys.
size_t Utf8Decode (WChar *c, const char *s)
size_t Utf8Encode (char *buf, WChar c)
size_t Utf8TrimString (char *s, size_t maxlen)
 Properly terminate an UTF8 string to some maximum length.
static WChar Utf8Consume (const char **s)
static size_t Utf8CharLen (WChar c)
 Return the length of a UTF-8 encoded character.
static size_t Utf8EncodedCharLen (char c)
 Return the length of an UTF-8 encoded value based on a single char.
static bool IsUtf8Part (char c)
static char * Utf8PrevChar (const char *s)
 Retrieve the previous UNICODE character in an UTF-8 encoded string.
static bool IsPrintable (WChar c)
static bool IsWhitespace (WChar c)
 Check whether UNICODE character is whitespace or not, i.e.


Detailed Description

Functions related to low-level strings.

Definition in file string_func.h.


Function Documentation

bool IsValidChar ( WChar  key,
CharSetFilter  afilter 
)

Only allow certain keys.

You can define the filter to be used. This makes sure no invalid keys can get into an editbox, like BELL.

Parameters:
key character to be checked
afilter the filter to use
Returns:
true or false depending if the character is printable/valid or not

Definition at line 145 of file string.cpp.

References CS_ALPHA, CS_ALPHANUMERAL, and CS_NUMERAL.

Referenced by IConsoleCmdExec(), and str_validate().

static bool IsWhitespace ( WChar  c  )  [inline, static]

Check whether UNICODE character is whitespace or not, i.e.

whether this is a potential line-break character.

Parameters:
c UNICODE character to check
Returns:
a boolean value whether 'c' is a whitespace character or not
See also:
http://www.fileformat.info/info/unicode/category/Zs/list.htm

Definition at line 151 of file string_func.h.

Referenced by FormatStringLinebreaks().

char* md5sumToString ( char *  buf,
const char *  last,
const uint8  md5sum[16] 
)

Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer.

Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer.

Parameters:
buf buffer to put the md5sum into
last last character of buffer (usually lastof(buf))
md5sum the md5sum itself
Returns:
a pointer to the next character after the md5sum

Definition at line 194 of file string.cpp.

Referenced by IsGoodGRFConfigList().

char* strecat ( char *  dst,
const char *  src,
const char *  last 
)

usage: strecpy(dst, src, lastof(dst));

Parameters:
dst destination buffer
src string to copy
last pointer to the last element in the dst array if NULL no boundary check is performed
Returns:
a pointer to the terminating in the destination buffer

Definition at line 34 of file string.cpp.

void strtolower ( char *  str  ) 

Convert the given string to lowercase, only works with ASCII!

Convert the given string to lowercase, only works with ASCII!

NOTE: only support ASCII characters, no UTF8 fancy. As currently the function is only used to lowercase data-filenames if they are not found, this is sufficient. If more, or general functionality is needed, look to r7271 where it was removed because it was broken when using certain locales: eg in Turkish the uppercase 'I' was converted to '?', so just revert to the old functionality

Parameters:
str string to convert

Definition at line 133 of file string.cpp.

Referenced by FioFOpenFile(), and TarListAddFile().

void ttd_strlcat ( char *  dst,
const char *  src,
size_t  size 
)

usage ttd_strlcpy(dst, src, lengthof(dst));

Parameters:
dst destination buffer
src string to copy/concatenate
size size of the destination buffer

Definition at line 16 of file string.cpp.

Referenced by BuildWithFullPath(), DoAutosave(), and GetDebugString().

static size_t Utf8CharLen ( WChar  c  )  [inline, static]

Return the length of a UTF-8 encoded character.

Parameters:
c Unicode character.
Returns:
Length of UTF-8 encoding for character.

Definition at line 84 of file string_func.h.

Referenced by FS2OTTD(), InsertTextBufferChar(), InsertTextBufferClipboard(), and UpdateTextBufferSize().

static size_t Utf8EncodedCharLen ( char  c  )  [inline, static]

Return the length of an UTF-8 encoded value based on a single char.

This char should be the first byte of the UTF-8 encoding. If not, or encoding is invalid, return value is 0

Parameters:
c char to query length of
Returns:
requested size

Definition at line 103 of file string_func.h.

References GB().

Referenced by Utf8TrimString().

static char* Utf8PrevChar ( const char *  s  )  [inline, static]

Retrieve the previous UNICODE character in an UTF-8 encoded string.

Parameters:
s char pointer pointing to (the first char of) the next character
Returns:
a pointer in 's' to the previous UNICODE character's first byte
Note:
The function should not be used to determine the length of the previous encoded char because it might be an invalid/corrupt start-sequence

Definition at line 128 of file string_func.h.

Referenced by FormatStringLinebreaks(), and MoveTextBufferPos().

size_t Utf8TrimString ( char *  s,
size_t  maxlen 
)

Properly terminate an UTF8 string to some maximum length.

Parameters:
s string to check if it needs additional trimming
maxlen the maximum length the buffer can have.
Returns:
the new length in bytes of the string (eg. strlen(new_string)) maxlen is the string length _INCLUDING_ the terminating ''

Definition at line 288 of file string.cpp.

References Utf8EncodedCharLen().


Generated on Mon Sep 22 20:34:27 2008 for openttd by  doxygen 1.5.6