X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fstring.qh;h=96e8a3a276258d568380219e0b1d8218ac9b7cf5;hb=d325a439c88154aa1f827bf274cc1b45fa46e5dc;hp=b05a316c94a2a4d6b438420d000ce7242f506f19;hpb=cabba6eeb71f3ca612aa30bb8c7dad9cbc9c0d52;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index b05a316c9..96e8a3a27 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -4,6 +4,25 @@ #include "sort.qh" #include "oo.qh" +// string logic +// +// true: is truthy +// == "": is equal to "" +// is "": has the same string index as the string constant "" +// strunzone: can be strunzoned +// +// | | true | == "" | is "" | strunzone | +// | :----------: | :--: | :---: | :---: | :-------: | +// | nil | | yes | | | +// | strcat(nil) | yes | yes | | | +// | strzone(nil) | yes | yes | | yes | +// | "" | yes | yes | yes | | +// | strcat("") | yes | yes | | | +// | strzone("") | yes | yes | | yes | +// | "s" | yes | | | | +// | strcat("s") | yes | | | | +// | strzone("s") | yes | | | yes | + #ifdef CSQC float stringwidth_colors(string s, vector theSize) { @@ -27,6 +46,20 @@ } #endif +#define strcpy(this, s) MACRO_BEGIN \ + if (this) { \ + strunzone(this); \ + } \ + this = strzone(s); \ +MACRO_END + +#define strfree(this) MACRO_BEGIN \ + if (this) { \ + strunzone(this); \ + } \ + this = string_null; \ +MACRO_END + ERASEABLE string seconds_tostring(float sec) { @@ -161,6 +194,14 @@ string cons(string a, string b) return strcat(a, " ", b); } +ERASEABLE +string cons_mid(string a, string mid, string b) +{ + if (a == "") return b; + if (b == "") return a; + return strcat(a, mid, b); +} + ERASEABLE string substring_range(string s, float b, float e) { @@ -256,6 +297,7 @@ int u8_strsize(string s) return l; } +//List of Unicode spaces: https://www.cs.tut.fi/~jkorpela/chars/spaces.html ERASEABLE bool isInvisibleString(string s) { @@ -272,8 +314,26 @@ bool isInvisibleString(string s) case 192: // charmap space if (!utf8) break; return false; - case 160: // space in unicode fonts case 0xE000 + 192: // utf8 charmap space + case 0x00A0: // NO-BREAK SPACE + //case 0x1680: // OGHAM SPACE MARK + case 0x180E: // MONGOLIAN VOWEL SEPARATOR + case 0x2000: // EN QUAD + case 0x2001: // EM QUAD + case 0x2002: // EN SPACE + case 0x2003: // EM SPACE + case 0x2004: // THREE-PER-EM SPACE + case 0x2005: // FOUR-PER-EM SPACE + case 0x2006: // SIX-PER-EM SPACE + case 0x2007: // FIGURE SPACE + case 0x2008: // PUNCTUATION SPACE + case 0x2009: // THIN SPACE + case 0x200A: // HAIR SPACE + case 0x200B: // ZERO WIDTH SPACE + case 0x202F: // NARROW NO-BREAK SPACE + case 0x205F: // MEDIUM MATHEMATICAL SPACE + case 0x3000: // IDEOGRAPHIC SPACE + case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE if (utf8) break; default: return false;