author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9146 | dbe2317185eb |
child 9390 | 88d36f907e96 |
permissions | -rw-r--r-- |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
2 |
|
8348 | 3 |
/** @file string_func.h Functions related to low-level strings. */ |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
4 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
5 |
#ifndef STRING_FUNC_H |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
6 |
#define STRING_FUNC_H |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
7 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
8 |
#include "core/bitmath_func.hpp" |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
9 |
#include "string_type.h" |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
10 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
11 |
/** |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
12 |
* usage ttd_strlcpy(dst, src, lengthof(dst)); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
13 |
* @param dst destination buffer |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
14 |
* @param src string to copy/concatenate |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
15 |
* @param size size of the destination buffer |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
16 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
17 |
void ttd_strlcat(char *dst, const char *src, size_t size); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
18 |
void ttd_strlcpy(char *dst, const char *src, size_t size); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
19 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
20 |
/** |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
21 |
* usage: strecpy(dst, src, lastof(dst)); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
22 |
* @param dst destination buffer |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
23 |
* @param src string to copy |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
24 |
* @param last pointer to the last element in the dst array |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
25 |
* if NULL no boundary check is performed |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
26 |
* @return a pointer to the terminating \0 in the destination buffer |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
27 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
28 |
char *strecat(char *dst, const char *src, const char *last); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
29 |
char *strecpy(char *dst, const char *src, const char *last); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
30 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
31 |
char *CDECL str_fmt(const char *str, ...); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
32 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
33 |
/** Scans the string for valid characters and if it finds invalid ones, |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
34 |
* replaces them with a question mark '?' */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
35 |
void str_validate(char *str); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
36 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
37 |
/** Scans the string for colour codes and strips them */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
38 |
void str_strip_colours(char *str); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
39 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
40 |
/** Convert the given string to lowercase, only works with ASCII! */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
41 |
void strtolower(char *str); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
42 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
43 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
44 |
static inline bool StrEmpty(const char *s) { return s == NULL || s[0] == '\0'; } |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
45 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
46 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
47 |
/** Get the length of a string, within a limited buffer */ |
9146
dbe2317185eb
(svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents:
8711
diff
changeset
|
48 |
static inline size_t ttd_strnlen(const char *str, size_t maxlen) |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
49 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
50 |
const char *t; |
9146
dbe2317185eb
(svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents:
8711
diff
changeset
|
51 |
for (t = str; *t != '\0' && (size_t)(t - str) < maxlen; t++) {} |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
52 |
return t - str; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
53 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
54 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
55 |
/** Convert the md5sum number to a 'hexadecimal' string, return next pos in buffer */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
56 |
char *md5sumToString(char *buf, const char *last, const uint8 md5sum[16]); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
57 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
58 |
/** |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
59 |
* Only allow certain keys. You can define the filter to be used. This makes |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
60 |
* sure no invalid keys can get into an editbox, like BELL. |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
61 |
* @param key character to be checked |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
62 |
* @param afilter the filter to use |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
63 |
* @return true or false depending if the character is printable/valid or not |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
64 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
65 |
bool IsValidChar(WChar key, CharSetFilter afilter); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
66 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
67 |
size_t Utf8Decode(WChar *c, const char *s); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
68 |
size_t Utf8Encode(char *buf, WChar c); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
69 |
size_t Utf8TrimString(char *s, size_t maxlen); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
70 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
71 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
72 |
static inline WChar Utf8Consume(const char **s) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
73 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
74 |
WChar c; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
75 |
*s += Utf8Decode(&c, *s); |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
76 |
return c; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
77 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
78 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
79 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
80 |
/** Return the length of a UTF-8 encoded character. |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
81 |
* @param c Unicode character. |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
82 |
* @return Length of UTF-8 encoding for character. |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
83 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
84 |
static inline size_t Utf8CharLen(WChar c) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
85 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
86 |
if (c < 0x80) return 1; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
87 |
if (c < 0x800) return 2; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
88 |
if (c < 0x10000) return 3; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
89 |
if (c < 0x110000) return 4; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
90 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
91 |
/* Invalid valid, we encode as a '?' */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
92 |
return 1; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
93 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
94 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
95 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
96 |
/** |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
97 |
* Return the length of an UTF-8 encoded value based on a single char. This |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
98 |
* char should be the first byte of the UTF-8 encoding. If not, or encoding |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
99 |
* is invalid, return value is 0 |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
100 |
* @param c char to query length of |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
101 |
* @return requested size |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
102 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
103 |
static inline size_t Utf8EncodedCharLen(char c) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
104 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
105 |
if (GB(c, 3, 5) == 0x1E) return 4; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
106 |
if (GB(c, 4, 4) == 0x0E) return 3; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
107 |
if (GB(c, 5, 3) == 0x06) return 2; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
108 |
if (GB(c, 7, 1) == 0x00) return 1; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
109 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
110 |
/* Invalid UTF8 start encoding */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
111 |
return 0; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
112 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
113 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
114 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
115 |
/* Check if the given character is part of a UTF8 sequence */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
116 |
static inline bool IsUtf8Part(char c) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
117 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
118 |
return GB(c, 6, 2) == 2; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
119 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
120 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
121 |
/** |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
122 |
* Retrieve the previous UNICODE character in an UTF-8 encoded string. |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
123 |
* @param s char pointer pointing to (the first char of) the next character |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
124 |
* @return a pointer in 's' to the previous UNICODE character's first byte |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
125 |
* @note The function should not be used to determine the length of the previous |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
126 |
* encoded char because it might be an invalid/corrupt start-sequence |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
127 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
128 |
static inline char *Utf8PrevChar(const char *s) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
129 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
130 |
const char *ret = s; |
8695
6607e9b9ffe2
(svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz
parents:
8348
diff
changeset
|
131 |
while (IsUtf8Part(*--ret)) {} |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
132 |
return (char*)ret; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
133 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
134 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
135 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
136 |
static inline bool IsPrintable(WChar c) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
137 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
138 |
if (c < 0x20) return false; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
139 |
if (c < 0xE000) return true; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
140 |
if (c < 0xE200) return false; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
141 |
return true; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
142 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
143 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
144 |
/** |
8711
1d6f1fd43e83
(svn r12385) -Fix [FS#ln]: Non-breaking spaces should not be broken.
peter1138
parents:
8695
diff
changeset
|
145 |
* Check whether UNICODE character is whitespace or not, i.e. whether |
1d6f1fd43e83
(svn r12385) -Fix [FS#ln]: Non-breaking spaces should not be broken.
peter1138
parents:
8695
diff
changeset
|
146 |
* this is a potential line-break character. |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
147 |
* @param c UNICODE character to check |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
148 |
* @return a boolean value whether 'c' is a whitespace character or not |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
149 |
* @see http://www.fileformat.info/info/unicode/category/Zs/list.htm |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
150 |
*/ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
151 |
static inline bool IsWhitespace(WChar c) |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
152 |
{ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
153 |
return |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
154 |
c == 0x0020 /* SPACE */ || |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
155 |
c == 0x3000 /* IDEOGRAPHIC SPACE */ |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
156 |
; |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
157 |
} |
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
158 |
|
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
diff
changeset
|
159 |
#endif /* STRING_FUNC_H */ |