Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Chris Müller
crystal
Commits
de77b3b3
Commit
de77b3b3
authored
Nov 02, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: rename utf8 functions for shorter names (chr,rchr,size,len,str).
parent
2fc7ef84
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
33 deletions
+60
-33
src/utf8.c
src/utf8.c
+25
-5
src/utf8.h
src/utf8.h
+8
-5
test/utf8.c
test/utf8.c
+27
-23
No files found.
src/utf8.c
View file @
de77b3b3
...
...
@@ -177,7 +177,7 @@
byte
*
cry_utf8_
str
chr
(
const
byte
*
str
,
unicode
character
)
cry_utf8_chr
(
const
byte
*
str
,
unicode
character
)
{
assert
(
str
!=
0
&&
(
UTF8_IS_SINGLE
(
*
str
)
||
UTF8_IS_LEAD
(
*
str
)));
unicode
ch
=
0
;
...
...
@@ -197,7 +197,7 @@ cry_utf8_strchr(const byte* str, unicode character)
byte
*
cry_utf8_
str
rchr
(
const
byte
*
str
,
unicode
character
)
cry_utf8_rchr
(
const
byte
*
str
,
unicode
character
)
{
assert
(
str
!=
0
&&
(
UTF8_IS_SINGLE
(
*
str
)
||
UTF8_IS_LEAD
(
*
str
)));
...
...
@@ -224,16 +224,36 @@ cry_utf8_strrchr(const byte* str, unicode character)
byte
*
cry_utf8_str
str
(
const
byte
*
str1
,
const
byte
*
str2
)
cry_utf8_str
(
const
byte
*
str1
,
const
byte
*
str2
)
{
assert
(
str1
!=
0
&&
(
UTF8_IS_SINGLE
(
*
str1
)
||
UTF8_IS_LEAD
(
*
str1
)));
const
byte
*
cp
=
str1
;
const
byte
*
s1
=
0
;
const
byte
*
s2
=
0
;
if
(
!*
str2
)
return
cry_cast
(
byte
*
,
str1
);
while
(
*
cp
)
{
s1
=
cp
;
s2
=
str2
;
while
(
*
s1
&&
*
s2
&&
!
(
*
s1
-
*
s2
))
s1
++
,
s2
++
;
if
(
!*
s2
)
return
cry_cast
(
byte
*
,
cp
);
++
cp
;
}
return
0
;
}
size_t
cry_utf8_
str
len
(
const
byte
*
str
)
cry_utf8_len
(
const
byte
*
str
)
{
assert
(
str
!=
0
&&
(
UTF8_IS_SINGLE
(
*
str
)
||
UTF8_IS_LEAD
(
*
str
)));
...
...
@@ -296,7 +316,7 @@ cry_utf8_prev(const byte* str)
size_t
cry_utf8_
str
size
(
const
byte
*
str
)
cry_utf8_size
(
const
byte
*
str
)
{
assert
(
str
!=
0
&&
(
UTF8_IS_SINGLE
(
*
str
)
||
UTF8_IS_LEAD
(
*
str
)));
...
...
src/utf8.h
View file @
de77b3b3
...
...
@@ -15,22 +15,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYSTAL_UTF8_H
#define CRYSTAL_UTF8_H
#include "standard.h"
int
cry_utf8_validate
(
const
byte
*
str
);
byte
*
cry_utf8_
str
chr
(
const
byte
*
str
,
unicode
character
);
byte
*
cry_utf8_
str
rchr
(
const
byte
*
str
,
unicode
character
);
byte
*
cry_utf8_str
str
(
const
byte
*
str1
,
const
byte
*
str2
);
byte
*
cry_utf8_chr
(
const
byte
*
str
,
unicode
character
);
byte
*
cry_utf8_rchr
(
const
byte
*
str
,
unicode
character
);
byte
*
cry_utf8_str
(
const
byte
*
str1
,
const
byte
*
str2
);
size_t
cry_utf8_
str
size
(
const
byte
*
str
);
size_t
cry_utf8_
str
len
(
const
byte
*
str
);
size_t
cry_utf8_size
(
const
byte
*
str
);
size_t
cry_utf8_len
(
const
byte
*
str
);
unicode
cry_utf8_get
(
const
byte
*
str
);
size_t
cry_utf8_codepoints
(
const
byte
*
str
);
byte
*
cry_utf8_next
(
const
byte
*
str
);
byte
*
cry_utf8_prev
(
const
byte
*
str
);
#endif // CRYSTAL_UTF8_H
test/utf8.c
View file @
de77b3b3
...
...
@@ -37,17 +37,17 @@ static void test_utf8_length(const_pointer data)
{
test_utf8_validate
(
data
);
assert
(
cry_utf8_
str
len
(
ascii
)
==
10
);
assert
(
cry_utf8_
str
len
(
latin1
)
==
16
);
assert
(
cry_utf8_
str
len
(
greek
)
==
4
);
assert
(
cry_utf8_
str
len
(
hiragana
)
==
4
);
assert
(
cry_utf8_
str
len
(
mixed
)
==
9
);
assert
(
cry_utf8_
str
size
(
ascii
)
==
10
);
assert
(
cry_utf8_
str
size
(
latin1
)
==
18
);
assert
(
cry_utf8_
str
size
(
greek
)
==
8
);
assert
(
cry_utf8_
str
size
(
hiragana
)
==
12
);
assert
(
cry_utf8_
str
size
(
mixed
)
==
17
);
assert
(
cry_utf8_len
(
ascii
)
==
10
);
assert
(
cry_utf8_len
(
latin1
)
==
16
);
assert
(
cry_utf8_len
(
greek
)
==
4
);
assert
(
cry_utf8_len
(
hiragana
)
==
4
);
assert
(
cry_utf8_len
(
mixed
)
==
9
);
assert
(
cry_utf8_size
(
ascii
)
==
10
);
assert
(
cry_utf8_size
(
latin1
)
==
18
);
assert
(
cry_utf8_size
(
greek
)
==
8
);
assert
(
cry_utf8_size
(
hiragana
)
==
12
);
assert
(
cry_utf8_size
(
mixed
)
==
17
);
}
...
...
@@ -92,20 +92,24 @@ static void test_utf8_search(const_pointer data)
test_utf8_validate
(
data
);
// forward search
assert
(
cry_utf8_
str
chr
(
ascii
,
's'
)
==
ascii
+
2
);
assert
(
cry_utf8_
str
chr
(
ascii
,
'g'
)
==
ascii
+
9
);
assert
(
cry_utf8_
str
chr
(
mixed
,
'z'
)
==
mixed
+
1
);
assert
(
cry_utf8_
str
chr
(
mixed
,
0x00E4
)
==
mixed
+
2
);
assert
(
cry_utf8_
str
chr
(
mixed
,
0x4ED0
)
==
mixed
+
5
);
assert
(
cry_utf8_
str
chr
(
mixed
,
0xFEC5
)
==
mixed
+
14
);
assert
(
cry_utf8_
str
chr
(
ascii
,
'P'
)
==
0
);
assert
(
cry_utf8_chr
(
ascii
,
's'
)
==
ascii
+
2
);
assert
(
cry_utf8_chr
(
ascii
,
'g'
)
==
ascii
+
9
);
assert
(
cry_utf8_chr
(
mixed
,
'z'
)
==
mixed
+
1
);
assert
(
cry_utf8_chr
(
mixed
,
0x00E4
)
==
mixed
+
2
);
assert
(
cry_utf8_chr
(
mixed
,
0x4ED0
)
==
mixed
+
5
);
assert
(
cry_utf8_chr
(
mixed
,
0xFEC5
)
==
mixed
+
14
);
assert
(
cry_utf8_chr
(
ascii
,
'P'
)
==
0
);
// reverse search
assert
(
cry_utf8_strrchr
(
ascii
,
's'
)
==
ascii
+
4
);
assert
(
cry_utf8_strrchr
(
latin1
,
'G'
)
==
latin1
);
assert
(
cry_utf8_strrchr
(
hiragana
,
0x305C
)
==
hiragana
);
assert
(
cry_utf8_strrchr
(
mixed
,
0x00E4
)
==
mixed
+
2
);
assert
(
cry_utf8_strrchr
(
ascii
,
'P'
)
==
0
);
assert
(
cry_utf8_rchr
(
ascii
,
's'
)
==
ascii
+
4
);
assert
(
cry_utf8_rchr
(
latin1
,
'G'
)
==
latin1
);
assert
(
cry_utf8_rchr
(
hiragana
,
0x305C
)
==
hiragana
);
assert
(
cry_utf8_rchr
(
mixed
,
0x00E4
)
==
mixed
+
2
);
assert
(
cry_utf8_rchr
(
ascii
,
'P'
)
==
0
);
//substrings
assert
(
cry_utf8_str
(
ascii
,
"string"
)
==
ascii
+
4
);
assert
(
cry_utf8_str
(
ascii
,
"nge"
)
==
0
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment