aboutsummaryrefslogtreecommitdiff
path: root/src/unicode.cpp
diff options
context:
space:
mode:
authorGinger Bill <github@gingerbill.org>2016-09-21 14:46:56 +0100
committerGinger Bill <github@gingerbill.org>2016-09-21 14:46:56 +0100
commit0e2347e582147019f904e25cf26aa70259c66e38 (patch)
tree4f3aff27dd23764d3c46afbfd94a4f65a87bc37c /src/unicode.cpp
parent31c11a50370ded9865cf8c1da6baabaa97d38a18 (diff)
Filename as default import name; as .; as _; panic()
Diffstat (limited to 'src/unicode.cpp')
-rw-r--r--src/unicode.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/unicode.cpp b/src/unicode.cpp
index cf415d86b..d8a26924c 100644
--- a/src/unicode.cpp
+++ b/src/unicode.cpp
@@ -39,3 +39,28 @@ b32 rune_is_whitespace(Rune r) {
}
return false;
}
+
+
+b32 is_string_an_identifier(String s) {
+ if (s.len < 1) {
+ return false;
+ }
+ isize offset = 0;
+ while (offset < s.len) {
+ b32 ok = false;
+ Rune r = -1;
+ isize size = gb_utf8_decode(s.text+offset, s.len-offset, &r);
+ if (offset == 0) {
+ ok = rune_is_letter(r);
+ } else {
+ ok = rune_is_letter(r) || rune_is_digit(r);
+ }
+
+ if (!ok) {
+ return false;
+ }
+ offset += size;
+ }
+
+ return offset == s.len;
+}