Skip to content

Commit

Permalink
FIX: length? of any-word!
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 31, 2020
1 parent 6618045 commit db4537c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/core/s-unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,20 @@ ConversionResult ConvertUTF8toUTF32 (
return dst;
}

/***********************************************************************
**
*/ REBCNT Length_As_UTF8_Code_Points(REBYTE *src)
/*
** Returns number of code points encoded in UTF-8.
**
***********************************************************************/
{
REBCNT size = 0;
while (*src) {
size += (*src++ & 0xC0) != 0x80;
}
return size;
}

/***********************************************************************
**
Expand Down
4 changes: 2 additions & 2 deletions src/core/t-word.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@

switch (action) {
case A_LENGTHQ:
diff = (REBINT)LEN_BYTES(Get_Sym_Name(VAL_WORD_SYM(val)));
if (type != REB_WORD) diff++;
diff = (REBINT)Length_As_UTF8_Code_Points(Get_Sym_Name(VAL_WORD_SYM(val)));
//if (type != REB_WORD) diff++; // in case that the _decoration_ should be also counted (#abc :abc abc: 'abc)
DS_Ret_Int(diff);
break;

Expand Down
1 change: 1 addition & 0 deletions src/tests/run-tests.r3
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dt [ ;- delta time
wrap load %units/tuple-test.r3
wrap load %units/typeset-test.r3
wrap load %units/vector-test.r3
wrap load %units/word-test.r3
;- cryptography tests:
wrap load %units/aes-test.r3
wrap load %units/chacha20-test.r3
Expand Down
25 changes: 25 additions & 0 deletions src/tests/units/word-test.r3
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Rebol [
Title: "Rebol3 word test script"
Author: "Oldes, Peter W A Wood"
File: %word-test.r3
Tabs: 4
Needs: [%../quick-test-module.r3]
]

~~~start-file~~~ "WORD!"

===start-group=== "word"
--test-- "Length? any-word!"
;@@ https://github.com/Oldes/Rebol-issues/issues/1740
;@@ https://github.com/Oldes/Rebol-issues/issues/2224
--assert 1 = length? #a
--assert 1 = length? 'a
--assert 1 = length? quote 'a
--assert 2 = length? #ša
--assert 2 = length? quote 'ša
--assert 1 = length? to-word to-string to-char 126
--assert 1 = length? to-word to-string to-char 128

===end-group===

~~~end-file~~~

0 comments on commit db4537c

Please sign in to comment.