Rationalize string lengths.

The .count getter on string returns the number of code points. That's
O(n), but it's consistent with the rest of the main string API.

If you want the number of bytes, it's "string".bytes.count.

Updated the docs.

Fixes 68. Woo!
This commit is contained in:
Bob Nystrom
2015-09-11 21:33:26 -07:00
parent c0b5ec9f15
commit fe143644b3
4 changed files with 78 additions and 30 deletions
-6
View File
@@ -1125,11 +1125,6 @@ DEF_PRIMITIVE(string_contains)
RETURN_BOOL(wrenStringFind(string, search) != UINT32_MAX);
}
DEF_PRIMITIVE(string_count)
{
RETURN_NUM(AS_STRING(args[0])->length);
}
DEF_PRIMITIVE(string_endsWith)
{
if (!validateString(vm, args, 1, "Argument")) return PRIM_ERROR;
@@ -1433,7 +1428,6 @@ void wrenInitializeCore(WrenVM* vm)
PRIMITIVE(vm->stringClass, "byteCount_", string_byteCount);
PRIMITIVE(vm->stringClass, "codePointAt_(_)", string_codePointAt);
PRIMITIVE(vm->stringClass, "contains(_)", string_contains);
PRIMITIVE(vm->stringClass, "count", string_count);
PRIMITIVE(vm->stringClass, "endsWith(_)", string_endsWith);
PRIMITIVE(vm->stringClass, "indexOf(_)", string_indexOf);
PRIMITIVE(vm->stringClass, "iterate(_)", string_iterate);