diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-11 22:54:51 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-11 22:54:51 +0000 |
| commit | f8afda3b221f6c2279a393c2c0fb8ab7ea1d59df (patch) | |
| tree | 650b932fc9e448dfe283932636195abf71c7d77b /src/string.cpp | |
| parent | 416413bebfcddf2b7ae2bf20fb01b675339297eb (diff) | |
Add more objc attributes
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 31 |
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; +} |