Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Unicode-strings/00-META.yaml
Normal file
2
Task/Unicode-strings/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Unicode_strings
|
||||
31
Task/Unicode-strings/00-TASK.txt
Normal file
31
Task/Unicode-strings/00-TASK.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
As the world gets smaller each day, internationalization becomes more and more important. For handling multiple languages, [[Unicode]] is your best friend.
|
||||
|
||||
It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings.
|
||||
|
||||
How well prepared is your programming language for Unicode?
|
||||
|
||||
|
||||
;Task:
|
||||
Discuss and demonstrate its unicode awareness and capabilities.
|
||||
|
||||
|
||||
Some suggested topics:
|
||||
:* How easy is it to present Unicode strings in source code?
|
||||
:* Can Unicode literals be written directly, or be part of identifiers/keywords/etc?
|
||||
:* How well can the language communicate with the rest of the world?
|
||||
:* Is it good at input/output with Unicode?
|
||||
:* Is it convenient to manipulate Unicode strings in the language?
|
||||
:* How broad/deep does the language support Unicode?
|
||||
:* What encodings (e.g. UTF-8, UTF-16, etc) can be used?
|
||||
:* Does it support normalization?
|
||||
|
||||
|
||||
;Note:
|
||||
This task is a bit unusual in that it encourages general discussion rather than clever coding.
|
||||
|
||||
|
||||
;See also:
|
||||
* [[Unicode variable names]]
|
||||
* [[Terminal control/Display an extended character]]
|
||||
<br><br>
|
||||
|
||||
301
Task/Unicode-strings/ALGOL-68/unicode-strings.alg
Normal file
301
Task/Unicode-strings/ALGOL-68/unicode-strings.alg
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
#!/usr/local/bin/a68g --script #
|
||||
# -*- coding: utf-8 -*- #
|
||||
|
||||
# UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #
|
||||
|
||||
MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 #
|
||||
MODE UNICODE = FLEX[0]UNICHAR;
|
||||
|
||||
OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out);
|
||||
OP INITUNICHAR = (CHAR char)UNICHAR: (UNICHAR out; bits OF out := BIN ABS char; out);
|
||||
OP INITBITS = (UNICHAR unichar)BITS: #BIN# bits OF unichar;
|
||||
|
||||
PROC raise value error = ([]UNION(FORMAT,BITS,STRING)argv )VOID: (
|
||||
putf(stand error, argv); stop
|
||||
);
|
||||
|
||||
MODE YIELDCHAR = PROC(CHAR)VOID; MODE GENCHAR = PROC(YIELDCHAR)VOID;
|
||||
MODE YIELDUNICHAR = PROC(UNICHAR)VOID; MODE GENUNICHAR = PROC(YIELDUNICHAR)VOID;
|
||||
|
||||
PRIO DOCONV = 1;
|
||||
|
||||
# Convert a stream of UNICHAR into a stream of UTFCHAR #
|
||||
OP DOCONV = (GENUNICHAR gen unichar, YIELDCHAR yield)VOID:(
|
||||
BITS non ascii = NOT 2r1111111;
|
||||
# FOR UNICHAR unichar IN # gen unichar( # ) DO ( #
|
||||
## (UNICHAR unichar)VOID: (
|
||||
BITS bits := INITBITS unichar;
|
||||
IF (bits AND non ascii) = 2r0 THEN # ascii #
|
||||
yield(REPR ABS bits)
|
||||
ELSE
|
||||
FLEX[6]CHAR buf := "?"*6; # initialise work around #
|
||||
INT bytes := 0;
|
||||
BITS byte lead bits = 2r10000000;
|
||||
FOR ofs FROM UPB buf BY -1 WHILE
|
||||
bytes +:= 1;
|
||||
buf[ofs]:= REPR ABS (byte lead bits OR bits AND 2r111111);
|
||||
bits := bits SHR 6;
|
||||
# WHILE # bits NE 2r0 DO
|
||||
SKIP
|
||||
OD;
|
||||
BITS first byte lead bits = BIN (ABS(2r1 SHL bytes)-2) SHL (UPB buf - bytes + 1);
|
||||
buf := buf[UPB buf-bytes+1:];
|
||||
buf[1] := REPR ABS(BIN ABS buf[1] OR first byte lead bits);
|
||||
FOR i TO UPB buf DO yield(buf[i]) OD
|
||||
FI
|
||||
# OD # ))
|
||||
);
|
||||
|
||||
# Convert a STRING into a stream of UNICHAR #
|
||||
OP DOCONV = (STRING string, YIELDUNICHAR yield)VOID: (
|
||||
PROC gen char = (YIELDCHAR yield)VOID:
|
||||
FOR i FROM LWB string TO UPB string DO yield(string[i]) OD;
|
||||
gen char DOCONV yield
|
||||
);
|
||||
|
||||
CO Prosser/Thompson UTF8 encoding scheme
|
||||
Bits Last code point Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
|
||||
7 U+007F 0xxxxxxx
|
||||
11 U+07FF 110xxxxx 10xxxxxx
|
||||
16 U+FFFF 1110xxxx 10xxxxxx 10xxxxxx
|
||||
21 U+1FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
26 U+3FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
31 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
END CO
|
||||
|
||||
# Quickly calculate the length of the UTF8 encoded string #
|
||||
PROC upb utf8 = (STRING utf8 string)INT:(
|
||||
INT bytes to go := 0;
|
||||
INT upb := 0;
|
||||
FOR i FROM LWB utf8 string TO UPB utf8 string DO
|
||||
CHAR byte := utf8 string[i];
|
||||
IF bytes to go = 0 THEN # start new utf char #
|
||||
bytes to go :=
|
||||
IF ABS byte <= ABS 2r01111111 THEN 1 # 7 bits #
|
||||
ELIF ABS byte <= ABS 2r11011111 THEN 2 # 11 bits #
|
||||
ELIF ABS byte <= ABS 2r11101111 THEN 3 # 16 bits #
|
||||
ELIF ABS byte <= ABS 2r11110111 THEN 4 # 21 bits #
|
||||
ELIF ABS byte <= ABS 2r11111011 THEN 5 # 26 bits #
|
||||
ELIF ABS byte <= ABS 2r11111101 THEN 6 # 31 bits #
|
||||
ELSE raise value error(("Invalid UTF-8 bytes", BIN ABS byte)); ~ FI
|
||||
FI;
|
||||
bytes to go -:= 1; # skip over trailing bytes #
|
||||
IF bytes to go = 0 THEN upb +:= 1 FI
|
||||
OD;
|
||||
upb
|
||||
);
|
||||
|
||||
# Convert a stream of CHAR into a stream of UNICHAR #
|
||||
OP DOCONV = (GENCHAR gen char, YIELDUNICHAR yield)VOID: (
|
||||
INT bytes to go := 0;
|
||||
INT lshift;
|
||||
BITS mask, out;
|
||||
|
||||
# FOR CHAR byte IN # gen char( # ) DO ( #
|
||||
## (CHAR byte)VOID: (
|
||||
INT bits := ABS byte;
|
||||
IF bytes to go = 0 THEN # start new unichar #
|
||||
bytes to go :=
|
||||
IF bits <= ABS 2r01111111 THEN 1 # 7 bits #
|
||||
ELIF bits <= ABS 2r11011111 THEN 2 # 11 bits #
|
||||
ELIF bits <= ABS 2r11101111 THEN 3 # 16 bits #
|
||||
ELIF bits <= ABS 2r11110111 THEN 4 # 21 bits #
|
||||
ELIF bits <= ABS 2r11111011 THEN 5 # 26 bits #
|
||||
ELIF bits <= ABS 2r11111101 THEN 6 # 31 bits #
|
||||
ELSE raise value error(("Invalid UTF-8 bytes", BIN bits)); ~ FI;
|
||||
IF bytes to go = 1 THEN
|
||||
lshift := 7; mask := 2r1111111
|
||||
ELSE
|
||||
lshift := 7 - bytes to go; mask := BIN(ABS(2r1 SHL lshift)-1)
|
||||
FI;
|
||||
out := mask AND BIN bits;
|
||||
|
||||
lshift := 6; mask := 2r111111 # subsequently pic 6 bits at a time #
|
||||
ELSE
|
||||
out := (out SHL lshift) OR ( mask AND BIN bits)
|
||||
FI;
|
||||
bytes to go -:= 1;
|
||||
IF bytes to go = 0 THEN yield(INITUNICHAR out) FI
|
||||
# OD # ))
|
||||
);
|
||||
|
||||
# Convert a string of UNICHAR into a stream of UTFCHAR #
|
||||
OP DOCONV = (UNICODE unicode, YIELDCHAR yield)VOID:(
|
||||
PROC gen unichar = (YIELDUNICHAR yield)VOID:
|
||||
FOR i FROM LWB unicode TO UPB unicode DO yield(unicode[i]) OD;
|
||||
gen unichar DOCONV yield
|
||||
);
|
||||
|
||||
# Some convenience/shorthand U operators #
|
||||
# Convert a BITS into a UNICODE char #
|
||||
OP U = (BITS bits)UNICHAR:
|
||||
INITUNICHAR bits;
|
||||
|
||||
# Convert a []BITS into a UNICODE char #
|
||||
OP U = ([]BITS array bits)[]UNICHAR:(
|
||||
[LWB array bits:UPB array bits]UNICHAR out;
|
||||
FOR i FROM LWB array bits TO UPB array bits DO bits OF out[i]:=array bits[i] OD;
|
||||
out
|
||||
);
|
||||
|
||||
# Convert a CHAR into a UNICODE char #
|
||||
OP U = (CHAR char)UNICHAR:
|
||||
INITUNICHAR char;
|
||||
|
||||
# Convert a STRING into a UNICODE string #
|
||||
OP U = (STRING utf8 string)UNICODE: (
|
||||
FLEX[upb utf8(utf8 string)]UNICHAR out;
|
||||
INT i := 0;
|
||||
# FOR UNICHAR char IN # utf8 string DOCONV (
|
||||
## (UNICHAR char)VOID:
|
||||
out[i+:=1] := char
|
||||
# OD #);
|
||||
out
|
||||
);
|
||||
|
||||
# Convert a UNICODE string into a UTF8 STRING #
|
||||
OP REPR = (UNICODE string)STRING: (
|
||||
STRING out;
|
||||
# FOR CHAR char IN # string DOCONV (
|
||||
## (CHAR char)VOID: (
|
||||
out +:= char
|
||||
# OD #));
|
||||
out
|
||||
);
|
||||
|
||||
# define the most useful OPerators on UNICODE CHARacter arrays #
|
||||
# Note: LWB, UPB and slicing works as per normal #
|
||||
|
||||
OP + = (UNICODE a,b)UNICODE: (
|
||||
[UPB a + UPB b]UNICHAR out;
|
||||
out[:UPB a]:= a; out[UPB a+1:]:= b;
|
||||
out
|
||||
);
|
||||
|
||||
OP + = (UNICODE a, UNICHAR b)UNICODE: a+UNICODE(b);
|
||||
OP + = (UNICHAR a, UNICODE b)UNICODE: UNICODE(a)+b;
|
||||
OP + = (UNICHAR a,b)UNICODE: UNICODE(a)+b;
|
||||
|
||||
# Suffix a character to the end of a UNICODE string #
|
||||
OP +:= = (REF UNICODE a, UNICODE b)VOID: a := a + b;
|
||||
OP +:= = (REF UNICODE a, UNICHAR b)VOID: a := a + b;
|
||||
|
||||
# Prefix a character to the beginning of a UNICODE string #
|
||||
OP +=: = (UNICODE b, REF UNICODE a)VOID: a := b + a;
|
||||
OP +=: = (UNICHAR b, REF UNICODE a)VOID: a := b + a;
|
||||
|
||||
OP * = (UNICODE a, INT n)UNICODE: (
|
||||
UNICODE out := a;
|
||||
FOR i FROM 2 TO n DO out +:= a OD;
|
||||
out
|
||||
);
|
||||
OP * = (INT n, UNICODE a)UNICODE: a * n;
|
||||
|
||||
OP * = (UNICHAR a, INT n)UNICODE: UNICODE(a)*n;
|
||||
OP * = (INT n, UNICHAR a)UNICODE: n*UNICODE(a);
|
||||
|
||||
OP *:= = (REF UNICODE a, INT b)VOID: a := a * b;
|
||||
|
||||
# Wirthy Operators #
|
||||
OP LT = (UNICHAR a,b)BOOL: ABS bits OF a LT ABS bits OF b,
|
||||
LE = (UNICHAR a,b)BOOL: ABS bits OF a LE ABS bits OF b,
|
||||
EQ = (UNICHAR a,b)BOOL: ABS bits OF a EQ ABS bits OF b,
|
||||
NE = (UNICHAR a,b)BOOL: ABS bits OF a NE ABS bits OF b,
|
||||
GE = (UNICHAR a,b)BOOL: ABS bits OF a GE ABS bits OF b,
|
||||
GT = (UNICHAR a,b)BOOL: ABS bits OF a GT ABS bits OF b;
|
||||
|
||||
# ASCII OPerators #
|
||||
OP < = (UNICHAR a,b)BOOL: a LT b,
|
||||
<= = (UNICHAR a,b)BOOL: a LE b,
|
||||
= = (UNICHAR a,b)BOOL: a EQ b,
|
||||
/= = (UNICHAR a,b)BOOL: a NE b,
|
||||
>= = (UNICHAR a,b)BOOL: a GE b,
|
||||
> = (UNICHAR a,b)BOOL: a GT b;
|
||||
|
||||
# Non ASCII OPerators
|
||||
OP ≤ = (UNICHAR a,b)BOOL: a LE b,
|
||||
≠ = (UNICHAR a,b)BOOL: a NE b,
|
||||
≥ = (UNICHAR a,b)BOOL: a GE b;
|
||||
#
|
||||
|
||||
# Compare two UNICODE strings for equality #
|
||||
PROC unicode cmp = (UNICODE str a,str b)INT: (
|
||||
|
||||
IF LWB str a > LWB str b THEN exit lt ELIF LWB str a < LWB str b THEN exit gt FI;
|
||||
|
||||
INT min upb = UPB(UPB str a < UPB str b | str a | str b );
|
||||
|
||||
FOR i FROM LWB str a TO min upb DO
|
||||
UNICHAR a := str a[i], UNICHAR b := str b[i];
|
||||
IF a < b THEN exit lt ELIF a > b THEN exit gt FI
|
||||
OD;
|
||||
|
||||
IF UPB str a > UPB str b THEN exit gt ELIF UPB str a < UPB str b THEN exit lt FI;
|
||||
|
||||
exit eq: 0 EXIT
|
||||
exit lt: -1 EXIT
|
||||
exit gt: 1
|
||||
);
|
||||
|
||||
OP LT = (UNICODE a,b)BOOL: unicode cmp(a,b)< 0,
|
||||
LE = (UNICODE a,b)BOOL: unicode cmp(a,b)<=0,
|
||||
EQ = (UNICODE a,b)BOOL: unicode cmp(a,b) =0,
|
||||
NE = (UNICODE a,b)BOOL: unicode cmp(a,b)/=0,
|
||||
GE = (UNICODE a,b)BOOL: unicode cmp(a,b)>=0,
|
||||
GT = (UNICODE a,b)BOOL: unicode cmp(a,b)> 0;
|
||||
|
||||
# ASCII OPerators #
|
||||
OP < = (UNICODE a,b)BOOL: a LT b,
|
||||
<= = (UNICODE a,b)BOOL: a LE b,
|
||||
= = (UNICODE a,b)BOOL: a EQ b,
|
||||
/= = (UNICODE a,b)BOOL: a NE b,
|
||||
>= = (UNICODE a,b)BOOL: a GE b,
|
||||
> = (UNICODE a,b)BOOL: a GT b;
|
||||
|
||||
# Non ASCII OPerators
|
||||
OP ≤ = (UNICODE a,b)BOOL: a LE b,
|
||||
≠ = (UNICODE a,b)BOOL: a NE b,
|
||||
≥ = (UNICODE a,b)BOOL: a GE b;
|
||||
#
|
||||
|
||||
COMMENT - Todo: for all UNICODE and UNICHAR
|
||||
Add NonASCII OPerators: ×, ×:=,
|
||||
Add ASCII Operators: &, &:=, &=:
|
||||
Add Wirthy OPerators: PLUSTO, PLUSAB, TIMESAB for UNICODE/UNICHAR,
|
||||
Add UNICODE against UNICHAR comparison OPerators,
|
||||
Add char_in_string and string_in_string PROCedures,
|
||||
Add standard Unicode functions:
|
||||
to_upper_case, to_lower_case, unicode_block, char_count,
|
||||
get_directionality, get_numeric_value, get_type, is_defined,
|
||||
is_digit, is_identifier_ignorable, is_iso_control,
|
||||
is_letter, is_letter_or_digit, is_lower_case, is_mirrored,
|
||||
is_space_char, is_supplementary_code_point, is_title_case,
|
||||
is_unicode_identifier_part, is_unicode_identifier_start,
|
||||
is_upper_case, is_valid_code_point, is_whitespace
|
||||
END COMMENT
|
||||
|
||||
test:(
|
||||
|
||||
UNICHAR aircraft := U16r 2708;
|
||||
printf(($"aircraft: "$, $"16r"16rdddd$, UNICODE(aircraft), $g$, " => ", REPR UNICODE(aircraft), $l$));
|
||||
|
||||
UNICODE chinese forty two = U16r 56db + U16r 5341 + U16r 4e8c;
|
||||
printf(($"chinese forty two: "$, $g$, REPR chinese forty two, ", length string = ", UPB chinese forty two, $l$));
|
||||
|
||||
UNICODE poker = U "A123456789♥♦♣♠JQK";
|
||||
printf(($"poker: "$, $g$, REPR poker, ", length string = ", UPB poker, $l$));
|
||||
|
||||
UNICODE selectric := U"×÷≤≥≠¬∨∧⏨→↓↑□⌊⌈⎩⎧○⊥¢";
|
||||
printf(($"selectric: "$, $g$, REPR selectric, $l$));
|
||||
printf(($"selectric*4: "$, $g$, REPR(selectric*4), $l$));
|
||||
|
||||
print((
|
||||
"1 < 2 is ", U"1" < U"2", ", ",
|
||||
"111 < 11 is ",U"111" < U"11", ", ",
|
||||
"111 < 12 is ",U"111" < U"12", ", ",
|
||||
"♥ < ♦ is ", U"♥" < U"♦", ", ",
|
||||
"♥Q < ♥K is ",U"♥Q" < U"♥K", " & ",
|
||||
"♥J < ♥K is ",U"♥J" < U"♥K", new line
|
||||
))
|
||||
|
||||
)
|
||||
7
Task/Unicode-strings/Arturo/unicode-strings.arturo
Normal file
7
Task/Unicode-strings/Arturo/unicode-strings.arturo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
text: "你好"
|
||||
|
||||
print ["text:" text]
|
||||
print ["length:" size text]
|
||||
print ["contains string '好'?:" contains? text "好"]
|
||||
print ["contains character '平'?:" contains? text `平`]
|
||||
print ["text as ascii:" as.ascii text]
|
||||
58
Task/Unicode-strings/BBC-BASIC/unicode-strings.basic
Normal file
58
Task/Unicode-strings/BBC-BASIC/unicode-strings.basic
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
VDU 23,22,640;512;8,16,16,128+8 : REM Select UTF-8 mode
|
||||
*FONT Times New Roman, 20
|
||||
|
||||
PRINT "Arabic:"
|
||||
|
||||
arabic1$ = "هنا مثال يمكنك من الكتابة من اليمين"
|
||||
arabic2$ = "الى اليسار باللغة العربية"
|
||||
|
||||
VDU 23,16,2;0;0;0;13 : REM Select right-to-left printing
|
||||
PRINT FNarabic(arabic1$) ' FNarabic(arabic2$)
|
||||
VDU 23,16,0;0;0;0;13 : REM Select left-to-right printing
|
||||
|
||||
PRINT '"Hebrew:"
|
||||
|
||||
hebrew$ = "זוהי הדגמה של כתיבת טקסט בעברית מימין לשמאל"
|
||||
|
||||
VDU 23,16,2;0;0;0;13 : REM Select right-to-left printing
|
||||
PRINT hebrew$
|
||||
VDU 23,16,0;0;0;0;13 : REM Select left-to-right printing
|
||||
|
||||
END
|
||||
|
||||
REM!Eject
|
||||
DEF FNarabic(A$)
|
||||
LOCAL A%, B%, L%, O%, P%, U%, B$
|
||||
A$ += CHR$0
|
||||
FOR A% = !^A$ TO !^A$+LENA$-1
|
||||
IF ?A%<&80 OR ?A%>=&C0 THEN
|
||||
L% = O% : O% = P% : P% = U%
|
||||
U% = ((?A% AND &3F) << 6) + (A%?1 AND &3F)
|
||||
IF ?A%<&80 U% = 0
|
||||
CASE TRUE OF
|
||||
WHEN U%=&60C OR U%=&61F: U% = 0
|
||||
WHEN U%<&622:
|
||||
WHEN U%<&626: U% = &01+2*(U%-&622)
|
||||
WHEN U%<&628: U% = &09+4*(U%-&626)
|
||||
WHEN U%<&62A: U% = &0F+4*(U%-&628)
|
||||
WHEN U%<&62F: U% = &15+4*(U%-&62A)
|
||||
WHEN U%<&633: U% = &29+2*(U%-&62F)
|
||||
WHEN U%<&63B: U% = &31+4*(U%-&633)
|
||||
WHEN U%<&641:
|
||||
WHEN U%<&648: U% = &51+4*(U%-&641)
|
||||
WHEN U%<&64B: U% = &6D+2*(U%-&648)
|
||||
ENDCASE
|
||||
IF P% IF P%<&80 THEN
|
||||
B% = P%
|
||||
IF O%=&5D IF P%<&5 B% += &74
|
||||
IF O%=&5D IF P%=&7 B% += &72
|
||||
IF O%=&5D IF P%=&D B% += &6E
|
||||
IF B%>P% B$=LEFT$(B$,LENB$-3) : O% = L%
|
||||
IF U% IF P%>7 IF P%<>&D IF P%<>&13 IF P%<>&29 IF P%<>&2B IF P%<>&2D IF P%<>&2F IF P%<>&6D IF P%<>&6F B% += 2
|
||||
IF O% IF O%>7 IF O%<>&D IF O%<>&13 IF O%<>&29 IF O%<>&2B IF O%<>&2D IF O%<>&2F IF O%<>&6D IF O%<>&6F B% += 1
|
||||
B$ = LEFT$(LEFT$(B$))+CHR$&EF+CHR$(&BA+(B%>>6))+CHR$(&80+(B%AND&3F))
|
||||
ENDIF
|
||||
ENDIF
|
||||
B$ += CHR$?A%
|
||||
NEXT
|
||||
= LEFT$(B$)
|
||||
30
Task/Unicode-strings/C/unicode-strings.c
Normal file
30
Task/Unicode-strings/C/unicode-strings.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
/* wchar_t is the standard type for wide chars; what it is internally
|
||||
* depends on the compiler.
|
||||
*/
|
||||
wchar_t poker[] = L"♥♦♣♠";
|
||||
wchar_t four_two[] = L"\x56db\x5341\x4e8c";
|
||||
|
||||
int main() {
|
||||
/* Set the locale to alert C's multibyte output routines */
|
||||
if (!setlocale(LC_CTYPE, "")) {
|
||||
fprintf(stderr, "Locale failure, check your env vars\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __STDC_ISO_10646__
|
||||
/* C99 compilers should understand these */
|
||||
printf("%lc\n", 0x2708); /* ✈ */
|
||||
printf("%ls\n", poker); /* ♥♦♣♠ */
|
||||
printf("%ls\n", four_two); /* 四十二 */
|
||||
#else
|
||||
/* oh well */
|
||||
printf("airplane\n");
|
||||
printf("club diamond club spade\n");
|
||||
printf("for ty two\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
2
Task/Unicode-strings/Common-Lisp/unicode-strings.lisp
Normal file
2
Task/Unicode-strings/Common-Lisp/unicode-strings.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defvar ♥♦♣♠ "♥♦♣♠")
|
||||
(defun ✈ () "a plane unicode function")
|
||||
22
Task/Unicode-strings/D/unicode-strings.d
Normal file
22
Task/Unicode-strings/D/unicode-strings.d
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import std.stdio;
|
||||
import std.uni; // standard package for normalization, composition/decomposition, etc..
|
||||
import std.utf; // standard package for decoding/encoding, etc...
|
||||
|
||||
void main() {
|
||||
// normal identifiers are allowed
|
||||
int a;
|
||||
// unicode characters are allowed for identifers
|
||||
int δ;
|
||||
|
||||
char c; // 1 to 4 byte unicode character
|
||||
wchar w; // 2 or 4 byte unicode character
|
||||
dchar d; // 4 byte unicode character
|
||||
|
||||
writeln("some text"); // strings by default are UTF8
|
||||
writeln("some text"c); // optional suffix for UTF8
|
||||
writeln("こんにちは"c); // unicode charcters are just fine (stored in the string type)
|
||||
writeln("Здравствуйте"w); // also avaiable are UTF16 string (stored in the wstring type)
|
||||
writeln("שלום"d); // and UTF32 strings (stored in the dstring type)
|
||||
|
||||
// escape sequences like what is defined in C are also allowed inside of strings and characters.
|
||||
}
|
||||
8
Task/Unicode-strings/Elena/unicode-strings.elena
Normal file
8
Task/Unicode-strings/Elena/unicode-strings.elena
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
public program()
|
||||
{
|
||||
var 四十二 := "♥♦♣♠"; // UTF8 string
|
||||
var строка := "Привет"w; // UTF16 string
|
||||
|
||||
console.writeLine:строка;
|
||||
console.writeLine:四十二;
|
||||
}
|
||||
5
Task/Unicode-strings/Go/unicode-strings-1.go
Normal file
5
Task/Unicode-strings/Go/unicode-strings-1.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var i int
|
||||
var u rune
|
||||
for i, u = range "voilà" {
|
||||
fmt.Println(i, u)
|
||||
}
|
||||
4
Task/Unicode-strings/Go/unicode-strings-2.go
Normal file
4
Task/Unicode-strings/Go/unicode-strings-2.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
w := "voilà"
|
||||
for i := 0; i < len(w); i++ {
|
||||
fmt.Println(i, w[i])
|
||||
}
|
||||
2
Task/Unicode-strings/J/unicode-strings-1.j
Normal file
2
Task/Unicode-strings/J/unicode-strings-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'♥♦♣♠'
|
||||
♥♦♣♠
|
||||
2
Task/Unicode-strings/J/unicode-strings-2.j
Normal file
2
Task/Unicode-strings/J/unicode-strings-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#'♥♦♣♠'
|
||||
12
|
||||
4
Task/Unicode-strings/J/unicode-strings-3.j
Normal file
4
Task/Unicode-strings/J/unicode-strings-3.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
7 u:'♥♦♣♠'
|
||||
♥♦♣♠
|
||||
#7 u:'♥♦♣♠'
|
||||
4
|
||||
2
Task/Unicode-strings/J/unicode-strings-4.j
Normal file
2
Task/Unicode-strings/J/unicode-strings-4.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'♥♦♣♠' -: 7 u:'♥♦♣♠'
|
||||
0
|
||||
2
Task/Unicode-strings/J/unicode-strings-5.j
Normal file
2
Task/Unicode-strings/J/unicode-strings-5.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'abcd'-:7 u:'abcd'
|
||||
1
|
||||
4
Task/Unicode-strings/J/unicode-strings-6.j
Normal file
4
Task/Unicode-strings/J/unicode-strings-6.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
'♥♦♣♠' -:&(7&u:) 7 u:'♥♦♣♠'
|
||||
1
|
||||
'♥♦♣♠' -:&(8&u:) 7 u:'♥♦♣♠'
|
||||
1
|
||||
3
Task/Unicode-strings/Julia/unicode-strings-1.julia
Normal file
3
Task/Unicode-strings/Julia/unicode-strings-1.julia
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
julia> 四十二 = "voilà";
|
||||
julia> println(四十二)
|
||||
voilà
|
||||
2
Task/Unicode-strings/Julia/unicode-strings-2.julia
Normal file
2
Task/Unicode-strings/Julia/unicode-strings-2.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
julia>println("\u2708")
|
||||
✈
|
||||
6
Task/Unicode-strings/Kotlin/unicode-strings.kotlin
Normal file
6
Task/Unicode-strings/Kotlin/unicode-strings.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// version 1.1.2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val åäö = "as⃝df̅ ♥♦♣♠ 頰"
|
||||
println(åäö)
|
||||
}
|
||||
2
Task/Unicode-strings/LFE/unicode-strings-1.lfe
Normal file
2
Task/Unicode-strings/LFE/unicode-strings-1.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (set encoded (binary ("åäö ð" utf8)))
|
||||
#B(195 165 195 164 195 182 32 195 176)
|
||||
2
Task/Unicode-strings/LFE/unicode-strings-2.lfe
Normal file
2
Task/Unicode-strings/LFE/unicode-strings-2.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (io:format "~tp~n" (list encoded))
|
||||
<<"åäö ð"/utf8>>
|
||||
2
Task/Unicode-strings/LFE/unicode-strings-3.lfe
Normal file
2
Task/Unicode-strings/LFE/unicode-strings-3.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (unicode:characters_to_list encoded 'utf8)
|
||||
"åäö ð"
|
||||
1
Task/Unicode-strings/Langur/unicode-strings.langur
Normal file
1
Task/Unicode-strings/Langur/unicode-strings.langur
Normal file
|
|
@ -0,0 +1 @@
|
|||
q:any"any code points here"
|
||||
7
Task/Unicode-strings/Lasso/unicode-strings.lasso
Normal file
7
Task/Unicode-strings/Lasso/unicode-strings.lasso
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
local(unicode = '♥♦♣♠')
|
||||
#unicode -> append('\u9830')
|
||||
#unicode
|
||||
'<br />'
|
||||
#unicode -> get (2)
|
||||
'<br />'
|
||||
#unicode -> get (4) -> integer
|
||||
10
Task/Unicode-strings/Lingo/unicode-strings.lingo
Normal file
10
Task/Unicode-strings/Lingo/unicode-strings.lingo
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
put _system.getInstalledCharSets()
|
||||
-- ["big5", "cp1026", "cp866", "ebcdic-cp-us", "gb2312", "ibm437", "ibm737",
|
||||
"ibm775", "ibm850", "ibm852", "ibm857", "ibm861", "ibm869", "iso-8859-1",
|
||||
"iso-8859-15", "iso-8859-2", "iso-8859-4", "iso-8859-5", "iso-8859-7",
|
||||
"iso-8859-9", "johab", "koi8-r", "koi8-u", "ks_c_5601-1987", "macintosh",
|
||||
"shift_jis", "us-ascii", "utf-16", "utf-16be", "utf-7", "utf-8", "windows-1250",
|
||||
"windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255",
|
||||
"windows-1256", "windows-1257", "windows-1258", "windows-874",
|
||||
"x-ebcdic-greekmodern", "x-mac-ce", "x-mac-cyrillic", "x-mac-greek",
|
||||
"x-mac-icelandic", "x-mac-turkish"]
|
||||
22
Task/Unicode-strings/Locomotive-Basic/unicode-strings.basic
Normal file
22
Task/Unicode-strings/Locomotive-Basic/unicode-strings.basic
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
10 CLS:DEFINT a-z
|
||||
20 ' define German umlauts as in Latin-1
|
||||
30 SYMBOL AFTER 196
|
||||
40 SYMBOL 196,&66,&18,&3C,&66,&7E,&66,&66,&0
|
||||
50 SYMBOL 214,&C6,&0,&7C,&C6,&C6,&C6,&7C,&0
|
||||
60 SYMBOL 220,&66,&0,&66,&66,&66,&66,&3C,&0
|
||||
70 SYMBOL 228,&6C,&0,&78,&C,&7C,&CC,&76,&0
|
||||
80 SYMBOL 246,&66,&0,&0,&3C,&66,&66,&3C,&0
|
||||
90 SYMBOL 252,&66,&0,&0,&66,&66,&66,&3E,&0
|
||||
100 SYMBOL 223,&38,&6C,&6C,&78,&6C,&78,&60,&0
|
||||
110 ' print string
|
||||
120 READ h
|
||||
130 IF h=0 THEN 180
|
||||
140 IF (h AND &X11100000)=&X11000000 THEN uc=(h AND &X11111)*2^6:GOTO 120
|
||||
150 IF (h AND &X11000000)=&X10000000 THEN uc=uc+(h AND &X111111):h=uc
|
||||
160 PRINT CHR$(h);
|
||||
170 GOTO 120
|
||||
180 PRINT
|
||||
190 END
|
||||
200 ' zero-terminated UTF-8 string
|
||||
210 DATA &48,&C3,&A4,&6C,&6C,&C3,&B6,&20,&4C,&C3,&BC,&64,&77,&69,&67,&2E,&20,&C3,&84,&C3,&96,&C3,&9C
|
||||
220 DATA &20,&C3,&A4,&C3,&B6,&C3,&BC,&20,&56,&69,&65,&6C,&65,&20,&47,&72,&C3,&BC,&C3,&9F,&65,&21,&00
|
||||
22
Task/Unicode-strings/M2000-Interpreter/unicode-strings.m2000
Normal file
22
Task/Unicode-strings/M2000-Interpreter/unicode-strings.m2000
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Font "Arial"
|
||||
Mode 32
|
||||
' M2000 internal editor can display left to rigtht languages if text is in same line, and same color.
|
||||
a$="لم أجد هذا الكتاب القديم"
|
||||
' We can use console to display text, using proportional spacing
|
||||
Print Part $(4), a$
|
||||
Print
|
||||
' We can display right to left using
|
||||
' the legend statement which render text at a given
|
||||
' graphic point, specify the font type and font size
|
||||
' and optional:
|
||||
' rotation angle, justification (1 for right,2 for center, 3 for left)
|
||||
'quality (0 or non 0, which 0 no antialliasing)
|
||||
' letter spacing in twips (not good for arabic language)
|
||||
move 6000,6000
|
||||
legend a$, "Arial", 32, pi/4, 2, 0
|
||||
' Variables can use any unicode letter.
|
||||
' Here we can't display it as in M2000 editor.
|
||||
' in the editor we see at the left the variable name
|
||||
' and at the right the value
|
||||
القديم=10
|
||||
Print القديم+1=11 ' true
|
||||
1
Task/Unicode-strings/Perl/unicode-strings-1.pl
Normal file
1
Task/Unicode-strings/Perl/unicode-strings-1.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
use utf8;
|
||||
3
Task/Unicode-strings/Perl/unicode-strings-2.pl
Normal file
3
Task/Unicode-strings/Perl/unicode-strings-2.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$四十二 = "voilà";
|
||||
print "$四十二"; # voilà
|
||||
print uc($四十二); # VOILÀ
|
||||
4
Task/Unicode-strings/Perl/unicode-strings-3.pl
Normal file
4
Task/Unicode-strings/Perl/unicode-strings-3.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use charnames qw(greek);
|
||||
$x = "\N{sigma} \U\N{sigma}";
|
||||
$y = "\x{2708}";
|
||||
print scalar reverse("$x $y"); # ✈ Σ σ
|
||||
1
Task/Unicode-strings/Perl/unicode-strings-4.pl
Normal file
1
Task/Unicode-strings/Perl/unicode-strings-4.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
print "Say עִבְרִית" =~ /(\p{BidiClass:R})/g; # עברית
|
||||
2
Task/Unicode-strings/Perl/unicode-strings-5.pl
Normal file
2
Task/Unicode-strings/Perl/unicode-strings-5.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
open IN, "<:utf8", "file_utf";
|
||||
open OUT, ">:raw", "file_byte";
|
||||
1
Task/Unicode-strings/PicoLisp/unicode-strings.l
Normal file
1
Task/Unicode-strings/PicoLisp/unicode-strings.l
Normal file
|
|
@ -0,0 +1 @@
|
|||
(in '(iconv "-f" "ISO-8859-15" "file.txt") (line))
|
||||
10
Task/Unicode-strings/Pike/unicode-strings.pike
Normal file
10
Task/Unicode-strings/Pike/unicode-strings.pike
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#charset utf8
|
||||
void main()
|
||||
{
|
||||
string nånsense = "\u03bb \0344 \n";
|
||||
string hello = "你好";
|
||||
string 水果 = "pineapple";
|
||||
string 真相 = sprintf("%s, %s goes really well on pizza\n", hello, 水果);
|
||||
write( string_to_utf8(真相) );
|
||||
write( string_to_utf8(nånsense) );
|
||||
}
|
||||
2
Task/Unicode-strings/PowerShell/unicode-strings.psh
Normal file
2
Task/Unicode-strings/PowerShell/unicode-strings.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# `u{x}
|
||||
"I`u{0307}" # => İ
|
||||
5
Task/Unicode-strings/Python/unicode-strings.py
Normal file
5
Task/Unicode-strings/Python/unicode-strings.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: latin-1 -*-
|
||||
|
||||
u = 'abcdé'
|
||||
print(ord(u[-1]))
|
||||
17
Task/Unicode-strings/Racket/unicode-strings.rkt
Normal file
17
Task/Unicode-strings/Racket/unicode-strings.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
|
||||
;; Unicode in strings, using ascii
|
||||
"\u03bb" ; -> "λ"
|
||||
;; and since Racket source code is read in UTF-8, Unicode can be used
|
||||
;; directly
|
||||
"λ" ; -> same
|
||||
|
||||
;; The same holds for character constants
|
||||
#\u3bb ; -> #\λ
|
||||
#\λ ; -> same
|
||||
|
||||
;; And of course Unicode can be used in identifiers,
|
||||
(define √ sqrt)
|
||||
(√ 256) ; -> 16
|
||||
;; and in fact the standard language makes use of some of these
|
||||
(λ(x) x) ; -> an identity function
|
||||
2
Task/Unicode-strings/Raku/unicode-strings.raku
Normal file
2
Task/Unicode-strings/Raku/unicode-strings.raku
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
sub prefix:<∛> (\𝐕) { 𝐕 ** ⅓ }
|
||||
say ∛27; # prints 3
|
||||
11
Task/Unicode-strings/Ring/unicode-strings.ring
Normal file
11
Task/Unicode-strings/Ring/unicode-strings.ring
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
see "Hello, World!"
|
||||
|
||||
func ringvm_see cText
|
||||
ring_see("I can play with the string before displaying it" + nl)
|
||||
ring_see("I can convert it :D" + nl)
|
||||
ring_see("Original Text: " + cText + nl)
|
||||
if cText = "Hello, World!"
|
||||
# Convert it from English to Hindi
|
||||
cText = "नमस्ते दुनिया!"
|
||||
ok
|
||||
ring_see("Converted To (Hindi): " + cText + nl)
|
||||
2
Task/Unicode-strings/Ruby/unicode-strings-1.rb
Normal file
2
Task/Unicode-strings/Ruby/unicode-strings-1.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
str = "你好"
|
||||
str.include?("好") # => true
|
||||
5
Task/Unicode-strings/Ruby/unicode-strings-2.rb
Normal file
5
Task/Unicode-strings/Ruby/unicode-strings-2.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def Σ(array)
|
||||
array.inject(:+)
|
||||
end
|
||||
|
||||
puts Σ([4,5,6]) #=>15
|
||||
4
Task/Unicode-strings/Ruby/unicode-strings-3.rb
Normal file
4
Task/Unicode-strings/Ruby/unicode-strings-3.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
p bad = "¿como\u0301 esta\u0301s?" # => "¿comó estás?"
|
||||
p bad.unicode_normalized? # => false
|
||||
p bad.unicode_normalize! # => "¿comó estás?"
|
||||
p bad.unicode_normalized? # => true
|
||||
28
Task/Unicode-strings/Scala/unicode-strings.scala
Normal file
28
Task/Unicode-strings/Scala/unicode-strings.scala
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
object UTF8 extends App {
|
||||
|
||||
def charToInt(s: String) = {
|
||||
def charToInt0(c: Char, next: Char): Option[Int] = (c, next) match {
|
||||
case _ if (c.isHighSurrogate && next.isLowSurrogate) =>
|
||||
Some(java.lang.Character.toCodePoint(c, next))
|
||||
case _ if (c.isLowSurrogate) => None
|
||||
case _ => Some(c.toInt)
|
||||
}
|
||||
|
||||
if (s.length > 1) charToInt0(s(0), s(1)) else Some(s.toInt)
|
||||
}
|
||||
|
||||
def intToChars(n: Int) = java.lang.Character.toChars(n).mkString
|
||||
|
||||
println('\uD869'.isHighSurrogate + " " + '\uDEA5'.isLowSurrogate)
|
||||
|
||||
println(charToInt("\uD869\uDEA5"))
|
||||
|
||||
val b = "\uD869\uDEA5"
|
||||
println(b)
|
||||
|
||||
val c = "\uD834\uDD1E"
|
||||
println(c)
|
||||
|
||||
val a = "$abcde¢£¤¥©ÇßçIJijŁłʒλπ•₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₵←→⇒∙⌘☺☻ア字文𪚥".
|
||||
map(c => "%s\t\\u%04X".format(c, c.toInt)).foreach(println)
|
||||
}
|
||||
19
Task/Unicode-strings/Sidef/unicode-strings.sidef
Normal file
19
Task/Unicode-strings/Sidef/unicode-strings.sidef
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# International class; name and street
|
||||
class 国際( なまえ, Straße ) {
|
||||
|
||||
# Say who am I!
|
||||
method 言え {
|
||||
say "I am #{self.なまえ} from #{self.Straße}";
|
||||
}
|
||||
}
|
||||
|
||||
# all the people of the world!
|
||||
var 民族 = [
|
||||
国際( "高田 Friederich", "台湾" ),
|
||||
国際( "Smith Σωκράτης", "Cantù" ),
|
||||
国際( "Stanisław Lec", "południow" ),
|
||||
];
|
||||
|
||||
民族.each { |garçon|
|
||||
garçon.言え;
|
||||
}
|
||||
15
Task/Unicode-strings/Swift/unicode-strings.swift
Normal file
15
Task/Unicode-strings/Swift/unicode-strings.swift
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
let flag = "🇵🇷"
|
||||
print(flag.characters.count)
|
||||
// Prints "1"
|
||||
print(flag.unicodeScalars.count)
|
||||
// Prints "2"
|
||||
print(flag.utf16.count)
|
||||
// Prints "4"
|
||||
print(flag.utf8.count)
|
||||
// Prints "8"
|
||||
|
||||
let nfc = "\u{01FA}"//Ǻ LATIN CAPITAL LETTER A WITH RING ABOVE AND ACUTE
|
||||
let nfd = "\u{0041}\u{030A}\u{0301}"//Latin Capital Letter A + ◌̊ COMBINING RING ABOVE + ◌́ COMBINING ACUTE ACCENT
|
||||
let nfkx = "\u{FF21}\u{030A}\u{0301}"//Fullwidth Latin Capital Letter A + ◌̊ COMBINING RING ABOVE + ◌́ COMBINING ACUTE ACCENT
|
||||
print(nfc == nfd) //NFx: true
|
||||
print(nfc == nfkx) //NFKx: false
|
||||
3
Task/Unicode-strings/TXR/unicode-strings.txr
Normal file
3
Task/Unicode-strings/TXR/unicode-strings.txr
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@{TITLE /[あ-ん一-耙]+/} (@ROMAJI/@ENGLISH)
|
||||
@(freeform)
|
||||
@(coll)@{STANZA /[^\n\x3000 ]+/}@(end)@/.*/
|
||||
1
Task/Unicode-strings/Vala/unicode-strings.vala
Normal file
1
Task/Unicode-strings/Vala/unicode-strings.vala
Normal file
|
|
@ -0,0 +1 @@
|
|||
stdout.printf ("UTF-8 encoded string. Let's go to a café!");
|
||||
22
Task/Unicode-strings/Visual-Basic-.NET/unicode-strings.vb
Normal file
22
Task/Unicode-strings/Visual-Basic-.NET/unicode-strings.vb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Module Module1
|
||||
|
||||
Sub Main()
|
||||
Console.OutputEncoding = Text.Encoding.Unicode
|
||||
|
||||
' normal identifiers allowed
|
||||
Dim a = 0
|
||||
' unicode characters allowed
|
||||
Dim δ = 1
|
||||
|
||||
' ascii strings
|
||||
Console.WriteLine("some text")
|
||||
' unicode strings strings
|
||||
Console.WriteLine("こんにちは")
|
||||
Console.WriteLine("Здравствуйте")
|
||||
Console.WriteLine("שלום")
|
||||
' escape sequences
|
||||
Console.WriteLine(vbTab + "text" + vbTab + ChrW(&H2708) + """blue")
|
||||
Console.ReadLine()
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
3
Task/Unicode-strings/WDTE/unicode-strings.wdte
Normal file
3
Task/Unicode-strings/WDTE/unicode-strings.wdte
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
let プリント t => io.writeln io.stdout t;
|
||||
|
||||
プリント 'これは実験です。';
|
||||
24
Task/Unicode-strings/Wren/unicode-strings.wren
Normal file
24
Task/Unicode-strings/Wren/unicode-strings.wren
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import "./upc" for Graphemes
|
||||
|
||||
var w = "voilà"
|
||||
for (c in w) {
|
||||
System.write("%(c) ") // prints the 5 Unicode 'characters'.
|
||||
}
|
||||
System.print("\nThe length of %(w) is %(w.count)")
|
||||
|
||||
|
||||
System.print("\nIts code-points are:")
|
||||
for (cp in w.codePoints) {
|
||||
System.write("%(cp) ") // prints the code-points as numbers
|
||||
}
|
||||
|
||||
System.print("\n\nIts bytes are: ")
|
||||
for (b in w.bytes) {
|
||||
System.write("%(b) ") // prints the bytes as numbers
|
||||
}
|
||||
|
||||
var zwe = "👨👩👧"
|
||||
System.print("\n\n%(zwe) has:")
|
||||
System.print(" %(zwe.bytes.count) bytes: %(zwe.bytes.toList.join(" "))")
|
||||
System.print(" %(zwe.codePoints.count) code-points: %(zwe.codePoints.toList.join(" "))")
|
||||
System.print(" %(Graphemes.clusterCount(zwe)) grapheme")
|
||||
Loading…
Add table
Add a link
Reference in a new issue