+//List of Unicode spaces: https://www.cs.tut.fi/~jkorpela/chars/spaces.html
+ERASEABLE
+bool isInvisibleString(string s)
+{
+ s = strdecolorize(s);
+ bool utf8 = cvar("utf8_enable");
+ for (int i = 0, n = strlen(s); i < n; ++i)
+ {
+ int c = str2chr(s, i);
+ switch (c)
+ {
+ case 0:
+ case 32: // space
+ break;
+ case 192: // charmap space
+ if (!utf8) break;
+ return false;
+ 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;
+ }
+ }
+ return true;
+}
+
+// Multiline text file buffers
+
+ERASEABLE
+int buf_load(string pFilename)
+{
+ int buf = buf_create();
+ if (buf < 0) return -1;
+ int fh = fopen(pFilename, FILE_READ);
+ if (fh < 0)
+ {
+ buf_del(buf);
+ return -1;
+ }
+ string l;
+ for (int i = 0; (l = fgets(fh)); ++i)
+ bufstr_set(buf, i, l);
+ fclose(fh);
+ return buf;
+}
+
+ERASEABLE
+void buf_save(float buf, string pFilename)
+{
+ int fh = fopen(pFilename, FILE_WRITE);
+ if (fh < 0) error(strcat("Can't write buf to ", pFilename));
+ int n = buf_getsize(buf);
+ for (int i = 0; i < n; ++i)
+ fputs(fh, strcat(bufstr_get(buf, i), "\n"));
+ fclose(fh);
+}
+
+/**
+ * converts a number to a string with the indicated number of decimals
+ */
+ERASEABLE
+string ftos_decimals(float number, int decimals)
+{
+ // inhibit stupid negative zero
+ if (number == 0) number = 0;
+ return sprintf("%.*f", decimals, number);
+}
+
+/**
+ * converts a number to a string with the minimum number of decimals
+ */
+ERASEABLE
+string ftos_mindecimals(float number)
+{
+ // inhibit stupid negative zero
+ if (number == 0) number = 0;
+ return sprintf("%.7g", number);
+}
+
+ERASEABLE
+int vercmp_recursive(string v1, string v2)
+{
+ int dot1 = strstrofs(v1, ".", 0);
+ int dot2 = strstrofs(v2, ".", 0);
+ string s1 = (dot1 == -1) ? v1 : substring(v1, 0, dot1);
+ string s2 = (dot2 == -1) ? v2 : substring(v2, 0, dot2);
+
+ float r;
+ r = stof(s1) - stof(s2);
+ if (r != 0) return r;
+
+ r = strcasecmp(s1, s2);
+ if (r != 0) return r;
+
+ if (dot1 == -1) return (dot2 == -1) ? 0 : -1;
+ else return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
+}
+
+ERASEABLE
+int vercmp(string v1, string v2)
+{
+ if (strcasecmp(v1, v2) == 0) return 0; // early out check
+
+ // "git" beats all
+ if (v1 == "git") return 1;
+ if (v2 == "git") return -1;
+
+ return vercmp_recursive(v1, v2);
+}
+
+const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef";
+const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";
+#define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))
+#define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
+#define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS_MINSET, (d), 1))
+#define IS_HEXDIGIT(d) (strstrofs(HEXDIGITS_MINSET, (d), 0) >= 0)
+
+const string DIGITS = "0123456789";
+#define IS_DIGIT(d) (strstrofs(DIGITS, (d), 0) >= 0)