aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-03-03 13:56:34 +0000
committergingerBill <bill@gingerbill.org>2022-03-03 13:56:34 +0000
commitfcab5508be19ac071a19f392bcd1824e3806af95 (patch)
tree770f7a3a85d94d56eae5f69cd4fb7e23d7d63c6d /src/string.cpp
parentad6ea3d6aa564ad228cf8883a8fd858135a16030 (diff)
parent0b05650366258a56c8da17848e238a21a377afb3 (diff)
Merge branch 'master' into odin-ast-changes
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp
index eb6058f78..bcaf23b9b 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -781,3 +781,34 @@ i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_retu
return 2;
}
+
+
+bool string_is_valid_identifier(String str) {
+ if (str.len <= 0) return false;
+
+ isize rune_count = 0;
+
+ isize w = 0;
+ isize offset = 0;
+ while (offset < str.len) {
+ Rune r = 0;
+ w = utf8_decode(str.text, str.len, &r);
+ if (r == GB_RUNE_INVALID) {
+ return false;
+ }
+
+ if (rune_count == 0) {
+ if (!rune_is_letter(r)) {
+ return false;
+ }
+ } else {
+ if (!rune_is_letter(r) && !rune_is_digit(r)) {
+ return false;
+ }
+ }
+ rune_count += 1;
+ offset += w;
+ }
+
+ return true;
+}