mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-30 23:23:07 +00:00 
			
		
		
		
	Address issue #180 - string/check-set
Fix the function and add test to further clarify that implementation is correct. Also fix empty string case.
This commit is contained in:
		| @@ -404,7 +404,6 @@ static Janet cfun_string_checkset(int32_t argc, Janet *argv) { | |||||||
|         bitset[index] |= mask; |         bitset[index] |= mask; | ||||||
|     } |     } | ||||||
|     /* Check set */ |     /* Check set */ | ||||||
|     if (str.len == 0) return janet_wrap_false(); |  | ||||||
|     for (int32_t i = 0; i < str.len; i++) { |     for (int32_t i = 0; i < str.len; i++) { | ||||||
|         int index = str.bytes[i] >> 5; |         int index = str.bytes[i] >> 5; | ||||||
|         uint32_t mask = 1 << (str.bytes[i] & 0x1F); |         uint32_t mask = 1 << (str.bytes[i] & 0x1F); | ||||||
| @@ -613,8 +612,9 @@ static const JanetReg string_cfuns[] = { | |||||||
|     { |     { | ||||||
|         "string/check-set", cfun_string_checkset, |         "string/check-set", cfun_string_checkset, | ||||||
|         JDOC("(string/check-set set str)\n\n" |         JDOC("(string/check-set set str)\n\n" | ||||||
|              "Checks if any of the bytes in the string set appear in the string str. " |              "Checks that the string str only contains bytes that appear in the string set. " | ||||||
|              "Returns true if some bytes in set do appear in str, false if no bytes do.") |              "Returns true if all bytes in str appear in set, false if some bytes in str do " | ||||||
|  |              "not appear in set.") | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|         "string/join", cfun_string_join, |         "string/join", cfun_string_join, | ||||||
|   | |||||||
| @@ -132,8 +132,9 @@ | |||||||
| (assert (string/check-set "abc" "a") "string/check-set 1") | (assert (string/check-set "abc" "a") "string/check-set 1") | ||||||
| (assert (not (string/check-set "abc" "z")) "string/check-set 2") | (assert (not (string/check-set "abc" "z")) "string/check-set 2") | ||||||
| (assert (string/check-set "abc" "abc") "string/check-set 3") | (assert (string/check-set "abc" "abc") "string/check-set 3") | ||||||
| (assert (not (string/check-set "abc" "")) "string/check-set 4") | (assert (string/check-set "abc" "") "string/check-set 4") | ||||||
| (assert (not (string/check-set "" "aabc")) "string/check-set 5") | (assert (not (string/check-set "" "aabc")) "string/check-set 5") | ||||||
|  | (assert (not (string/check-set "abc" "abcdefg")) "string/check-set 6") | ||||||
|  |  | ||||||
| # Marshal and unmarshal pegs | # Marshal and unmarshal pegs | ||||||
| (def p (-> "abcd" peg/compile marshal unmarshal)) | (def p (-> "abcd" peg/compile marshal unmarshal)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose