diff options
Diffstat (limited to 'src/lj_str.c')
-rw-r--r-- | src/lj_str.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index 675213d7..f5bbae26 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
@@ -16,7 +16,7 @@ | |||
16 | #include "lj_state.h" | 16 | #include "lj_state.h" |
17 | #include "lj_char.h" | 17 | #include "lj_char.h" |
18 | 18 | ||
19 | /* -- String interning ---------------------------------------------------- */ | 19 | /* -- String helpers ------------------------------------------------------ */ |
20 | 20 | ||
21 | /* Ordered compare of strings. Assumes string data is 4-byte aligned. */ | 21 | /* Ordered compare of strings. Assumes string data is 4-byte aligned. */ |
22 | int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) | 22 | int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) |
@@ -62,6 +62,40 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) | |||
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | /* Find fixed string p inside string s. */ | ||
66 | const char *lj_str_find(const char *s, const char *p, MSize slen, MSize plen) | ||
67 | { | ||
68 | if (plen <= slen) { | ||
69 | if (plen == 0) { | ||
70 | return s; | ||
71 | } else { | ||
72 | int c = *(const uint8_t *)p++; | ||
73 | plen--; slen -= plen; | ||
74 | while (slen) { | ||
75 | const char *q = (const char *)memchr(s, c, slen); | ||
76 | if (!q) break; | ||
77 | if (memcmp(q+1, p, plen) == 0) return q; | ||
78 | q++; slen -= (MSize)(q-s); s = q; | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | return NULL; | ||
83 | } | ||
84 | |||
85 | /* Check whether a string has a pattern matching character. */ | ||
86 | int lj_str_haspattern(GCstr *s) | ||
87 | { | ||
88 | const char *p = strdata(s), *q = p + s->len; | ||
89 | while (p < q) { | ||
90 | int c = *(const uint8_t *)p++; | ||
91 | if (lj_char_ispunct(c) && strchr("^$*+?.([%-", c)) | ||
92 | return 1; /* Found a pattern matching char. */ | ||
93 | } | ||
94 | return 0; /* No pattern matching chars found. */ | ||
95 | } | ||
96 | |||
97 | /* -- String interning ---------------------------------------------------- */ | ||
98 | |||
65 | /* Resize the string hash table (grow and shrink). */ | 99 | /* Resize the string hash table (grow and shrink). */ |
66 | void lj_str_resize(lua_State *L, MSize newmask) | 100 | void lj_str_resize(lua_State *L, MSize newmask) |
67 | { | 101 | { |