Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- String manipulation
from: http://rosettacode.org/wiki/String_length
note: Basic language learning

View file

@ -0,0 +1,23 @@
;Task:
Find the <em>character</em> and <em>byte</em> length of a string.
This means encodings like [[UTF-8]] need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters.
By ''character'', we mean an individual Unicode ''code point'', not a user-visible ''grapheme'' containing combining characters.
For example, the character length of "møøse" is 5 but the byte length is 7 in UTF-8 and 10 in UTF-16.
Non-BMP code points (those between 0x10000 and 0x10FFFF) must also be handled correctly: answers should produce actual character counts in code points, not in code unit counts.
Therefore a string like "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" (consisting of the 7 Unicode characters U+1D518 U+1D52B U+1D526 U+1D520 U+1D52C U+1D521 U+1D522) is 7 characters long, '''not''' 14 UTF-16 code units; and it is 28 bytes long whether encoded in UTF-8 or in UTF-16.
Please mark your examples with <nowiki>===Character Length=== or ===Byte Length===</nowiki>.
If your language is capable of providing the string length in graphemes, mark those examples with <nowiki>===Grapheme Length===</nowiki>.
For example, the string "J̲o̲s̲é̲" ("J\x{332}o\x{332}s\x{332}e\x{301}\x{332}") has 4 user-visible graphemes, 9 characters (code points), and 14 bytes when encoded in UTF-8.
<br><br>
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1,25 @@
* String length 06/07/2016
LEN CSECT
USING LEN,15 base register
LA 1,L'C length of C
XDECO 1,PG
XPRNT PG,12
LA 1,L'H length of H
XDECO 1,PG
XPRNT PG,12
LA 1,L'F length of F
XDECO 1,PG
XPRNT PG,12
LA 1,L'D length of D
XDECO 1,PG
XPRNT PG,12
LA 1,L'PG length of PG
XDECO 1,PG
XPRNT PG,12
BR 14 exit length
C DS C character 1
H DS H half word 2
F DS F full word 4
D DS D double word 8
PG DS CL12 string 12
END LEN

View file

@ -0,0 +1 @@
$length:=Length("Hello, world!")

View file

@ -0,0 +1,12 @@
GetStringLength: ;$00 and $01 make up the pointer to the string's base address.
;(Of course, any two consecutive zero-page memory locations can fulfill this role.)
LDY #0 ;Y is both the index into the string and the length counter.
loop_getStringLength:
LDA ($00),y
BEQ exit
INY
JMP loop_getStringLength
exit:
RTS ;string length is now loaded into Y.

View file

@ -0,0 +1,15 @@
GetStringLength:
; INPUT: A3 = BASE ADDRESS OF STRING
; RETURNS LENGTH IN D1 (MEASURED IN BYTES)
MOVE.L #0,D1
loop_getStringLength:
MOVE.B (A3)+,D0
CMP #0,D0
BEQ done
ADDQ.L #1,D1
BRA loop_getStringLength
done:
RTS

View file

@ -0,0 +1,15 @@
;INPUT: DS:SI = BASE ADDR. OF STRING
;TYPICALLY, MS-DOS USES $ TO TERMINATE STRINGS.
GetStringLength:
xor cx,cx ;this takes fewer bytes to encode than "mov cx,0"
cld ;makes string functions post-inc rather than post-dec.
loop_GetStringLength:
lodsb ;equivalent of "mov al,[ds:si],inc si" except this doesn't alter the flags.
cmp '$'
je done ;if equal, we're finished.
inc cx ;add 1 to length counter. A null string will have a length of zero.
jmp loop_GetStringLength
done:
ret

View file

@ -0,0 +1,98 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program stringLength64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResultByte: .asciz "===Byte Length=== : @ \n"
sMessResultChar: .asciz "===Character Length=== : @ \n"
szString1: .asciz "møøse€"
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
ldr x0,qAdrszString1
bl affichageMess // display string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString1
mov x1,#0
1: // loop compute length bytes
ldrb w2,[x0,x1]
cmp w2,#0
cinc x1,x1,ne
bne 1b
mov x0,x1 // result display
ldr x1,qAdrsZoneConv
bl conversion10 // call decimal conversion
ldr x0,qAdrsMessResultByte
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess
ldr x0,qAdrszString1
mov x1,#0
mov x3,#0
2: // loop compute length characters
ldrb w2,[x0,x1]
cmp w2,#0
beq 6f
and x2,x2,#0b11100000 // 3 bytes ?
cmp x2,#0b11100000
bne 3f
add x3,x3,#1
add x1,x1,#3
b 2b
3:
and x2,x2,#0b11000000 // 2 bytes ?
cmp x2,#0b11000000
bne 4f
add x3,x3,#1
add x1,x1,#2
b 2b
4: // else 1 byte
add x3,x3,#1
add x1,x1,#1
b 2b
6:
mov x0,x3
ldr x1,qAdrsZoneConv
bl conversion10 // call decimal conversion
ldr x0,qAdrsMessResultChar
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsMessResultByte: .quad sMessResultByte
qAdrsMessResultChar: .quad sMessResultChar
qAdrszString1: .quad szString1
qAdrsZoneConv: .quad sZoneConv
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,7 @@
BITS bits := bits pack((TRUE, TRUE, FALSE, FALSE)); # packed array of BOOL #
BYTES bytes := bytes pack("Hello, world"); # packed array of CHAR #
print((
"BITS and BYTES are fixed width:", new line,
"bits width:", bits width, ", max bits: ", max bits, ", bits:", bits, new line,
"bytes width: ",bytes width, ", UPB:",UPB STRING(bytes), ", string:", STRING(bytes),"!", new line
))

View file

@ -0,0 +1,7 @@
STRING str := "hello, world";
INT length := UPB str;
printf(($"Length of """g""" is "g(3)l$,str,length));
printf(($l"STRINGS can start at -1, in which case LWB must be used:"l$));
STRING s := "abcd"[@-1];
print(("s:",s, ", LWB:", LWB s, ", UPB:",UPB s, ", LEN:",UPB s - LWB s + 1))

View file

@ -0,0 +1,102 @@
/* ARM assembly Raspberry PI */
/* program stringLength.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResultByte: .asciz "===Byte Length=== : @ \n"
sMessResultChar: .asciz "===Character Length=== : @ \n"
szString1: .asciz "møøse€"
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrszString1
bl affichageMess @ display string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString1
mov r1,#0
1: @ loop compute length bytes
ldrb r2,[r0,r1]
cmp r2,#0
addne r1,#1
bne 1b
mov r0,r1 @ result display
ldr r1,iAdrsZoneConv
bl conversion10 @ call decimal conversion
ldr r0,iAdrsMessResultByte
ldr r1,iAdrsZoneConv @ insert conversion in message
bl strInsertAtCharInc
bl affichageMess
ldr r0,iAdrszString1
mov r1,#0
mov r3,#0
2: @ loop compute length characters
ldrb r2,[r0,r1]
cmp r2,#0
beq 6f
and r2,#0b11100000 @ 3 bytes ?
cmp r2,#0b11100000
bne 3f
add r3,#1
add r1,#3
b 2b
3:
and r2,#0b11000000 @ 2 bytes ?
cmp r2,#0b11000000
bne 4f
add r3,#1
add r1,#2
b 2b
4: @ else 1 byte
add r3,#1
add r1,#1
b 2b
6:
mov r0,r3
ldr r1,iAdrsZoneConv
bl conversion10 @ call decimal conversion
ldr r0,iAdrsMessResultChar
ldr r1,iAdrsZoneConv @ insert conversion in message
bl strInsertAtCharInc
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsMessResultByte: .int sMessResultByte
iAdrsMessResultChar: .int sMessResultChar
iAdrszString1: .int szString1
iAdrsZoneConv: .int sZoneConv
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"

View file

@ -0,0 +1,4 @@
w=length("Hello, world!") # static string example
x=length("Hello," s " world!") # dynamic string example
y=length($1) # input field example
z=length(s) # variable name example

View file

@ -0,0 +1,2 @@
#!/usr/bin/awk -f
{print"The length of this line is "length($0)}

View file

@ -0,0 +1,8 @@
PROC Test(CHAR ARRAY s)
PrintF("Length of ""%S"" is %B%E",s,s(0))
RETURN
PROC Main()
Test("Hello world!")
Test("")
RETURN

View file

@ -0,0 +1,34 @@
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.ByteArray;
public class StringByteLength extends Sprite {
public function StringByteLength() {
if ( stage ) _init();
else addEventListener(Event.ADDED_TO_STAGE, _init);
}
private function _init(e:Event = null):void {
var s1:String = "The quick brown fox jumps over the lazy dog";
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
var s3:String = "José";
var b:ByteArray = new ByteArray();
b.writeUTFBytes(s1);
trace(b.length); // 43
b.clear();
b.writeUTFBytes(s2);
trace(b.length); // 28
b.clear();
b.writeUTFBytes(s3);
trace(b.length); // 5
}
}
}

View file

@ -0,0 +1,4 @@
var s1:String = "The quick brown fox jumps over the lazy dog";
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
var s3:String = "José";
trace(s1.length, s2.length, s3.length); // 43, 14, 4

View file

@ -0,0 +1,2 @@
Str : String := "Hello World";
Length : constant Natural := Str'Size / 8;

View file

@ -0,0 +1,6 @@
Latin_1_Str : String := "Hello World";
UCS_16_Str : Wide_String := "Hello World";
Unicode_Str : Wide_Wide_String := "Hello World";
Latin_1_Length : constant Natural := Latin_1_Str'Length;
UCS_16_Length : constant Natural := UCS_16_Str'Length;
Unicode_Length : constant Natural := Unicode_Str'Length;

View file

@ -0,0 +1 @@
length("Hello, World!")

View file

@ -0,0 +1 @@
~"Hello, World!"

View file

@ -0,0 +1,2 @@
String myString = 'abcd';
System.debug('Size of String', myString.length());

View file

@ -0,0 +1 @@
count of "Hello World"

View file

@ -0,0 +1,32 @@
set inString to "Hello é̦世界"
set byteCount to 0
repeat with c in inString
set t to id of c
if ((count of t) > 0) then
repeat with i in t
set byteCount to byteCount + doit(i)
end repeat
else
set byteCount to byteCount + doit(t)
end if
end repeat
byteCount
on doit(cid)
set n to (cid as integer)
if n > 67108863 then -- 0x3FFFFFF
return 6
else if n > 2097151 then -- 0x1FFFFF
return 5
else if n > 65535 then -- 0xFFFF
return 4
else if n > 2047 then -- 0x07FF
return 3
else if n > 127 then -- 0x7F
return 2
else
return 1
end if
end doit

View file

@ -0,0 +1 @@
count of "Hello World"

View file

@ -0,0 +1 @@
count "Hello World"

View file

@ -0,0 +1 @@
? LEN("HELLO, WORLD!")

View file

@ -0,0 +1,3 @@
str: "Hello World"
print ["length =" size str]

View file

@ -0,0 +1 @@
Msgbox % StrLen("Hello World")

View file

@ -0,0 +1,3 @@
String := "Hello World"
StringLen, Length, String
Msgbox % Length

View file

@ -0,0 +1 @@
|"møøse"|

View file

@ -0,0 +1,7 @@
nonBMPString ::= "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
encoder ::= a UTF8 encoder;
bytes ::= encoder process nonBMPString;
|bytes|
// or, as a one-liner
|a UTF8 encoder process "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"|

View file

@ -0,0 +1,2 @@
"HELLO, WORLD"→Str1
Disp length(Str1)▶Dec,i

View file

@ -0,0 +1,2 @@
INPUT a$
PRINT LEN(a$)

View file

@ -0,0 +1,2 @@
INPUT text$
PRINT LEN(text$)

View file

@ -0,0 +1,12 @@
CP_ACP = 0
CP_UTF8 = &FDE9
textA$ = "møøse"
textW$ = " "
textU$ = " "
SYS "MultiByteToWideChar", CP_ACP, 0, textA$, -1, !^textW$, LEN(textW$)/2 TO nW%
SYS "WideCharToMultiByte", CP_UTF8, 0, textW$, -1, !^textU$, LEN(textU$), 0, 0
PRINT "Length in bytes (ANSI encoding) = " ; LEN(textA$)
PRINT "Length in bytes (UTF-16 encoding) = " ; 2*(nW%-1)
PRINT "Length in bytes (UTF-8 encoding) = " ; LEN($$!^textU$)

View file

@ -0,0 +1 @@
BLen {(𝕩)+´𝕩@+128204865536}

View file

@ -0,0 +1 @@
Len

View file

@ -0,0 +1,5 @@
•Show >(LenBLen)¨
"møøse"
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
"J̲o̲s̲é̲"

View file

@ -0,0 +1,5 @@
"møøse" 5 7
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢" 7 28
"J̲o̲s̲é̲" 8 13

View file

@ -0,0 +1,8 @@
PRINT "Bytelen of 'hello': ", LEN("hello")
PRINT "Charlen of 'hello': ", ULEN("hello")
PRINT "Bytelen of 'møøse': ", LEN("møøse")
PRINT "Charlen of 'møøse': ", ULEN("møøse")
PRINT "Bytelen of '𝔘𝔫𝔦𝔠𝔬𝔡𝔢': ", LEN("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")
PRINT "Charlen of '𝔘𝔫𝔦𝔠𝔬𝔡𝔢': ", ULEN("𝔘𝔫𝔦𝔠𝔬𝔡𝔢")

View file

@ -0,0 +1,17 @@
@echo off
setlocal enabledelayedexpansion
call :length %1 res
echo length of %1 is %res%
goto :eof
:length
set str=%~1
set cnt=0
:loop
if "%str%" equ "" (
set %2=%cnt%
goto :eof
)
set str=!str:~1!
set /a cnt = cnt + 1
goto loop

View file

@ -0,0 +1,7 @@
(ByteLength=
length
. @(!arg:? [?length)
& !length
);
out$ByteLength$𝔘𝔫𝔦𝔠𝔬𝔡𝔢

View file

@ -0,0 +1,16 @@
(CharacterLength=
length c
. 0:?length
& @( !arg
: ?
( %?c
& utf$!c:?k
& 1+!length:?length
& ~
)
?
)
| !length
);
out$CharacterLength$𝔘𝔫𝔦𝔠𝔬𝔡𝔢

View file

@ -0,0 +1,14 @@
(CharacterLength=
length c p
. 0:?length:?p
& @( !arg
: ?
( [!p %?c
& utf$!c:?k
& 1+!length:?length
)
([?p&~)
?
)
| !length
);

View file

@ -0,0 +1,4 @@
(CharacterLength=
length
. vap$((=.!arg).!arg):? [?length&!length
);

View file

@ -0,0 +1,6 @@
,----- ----- [>,----- -----] ; read a text until a newline
<[+++++ +++++<] ; restore the original text
>[[-]<[>+<-]>+>]< ; add one to the accumulator cell for every byte read
;; from esolang dot org
>[-]>[-]+>[-]+< [>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[-]> [-]<<<<<[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++ [-<++++++>]>>[-<<+>>]<<] <[.[-]<]
[-]+++++ +++++. ; print newline

View file

@ -0,0 +1,11 @@
#include <string> // (not <string.h>!)
using std::string;
int main()
{
string s = "Hello, world!";
string::size_type length = s.length(); // option 1: In Characters/Bytes
string::size_type size = s.size(); // option 2: In Characters/Bytes
// In bytes same as above since sizeof(char) == 1
string::size_type bytes = s.length() * sizeof(string::value_type);
}

View file

@ -0,0 +1,8 @@
#include <string>
using std::wstring;
int main()
{
wstring s = L"\u304A\u306F\u3088\u3046";
wstring::size_type length = s.length() * sizeof(wstring::value_type); // in bytes
}

View file

@ -0,0 +1,8 @@
#include <string>
using std::wstring;
int main()
{
wstring s = L"\u304A\u306F\u3088\u3046";
wstring::size_type length = s.length();
}

View file

@ -0,0 +1,9 @@
#include <iostream>
#include <codecvt>
int main()
{
std::string utf8 = "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; // U+007a, U+00df, U+6c34, U+1d10b
std::cout << "Byte length: " << utf8.size() << '\n';
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
std::cout << "Character length: " << conv.from_bytes(utf8).size() << '\n';
}

View file

@ -0,0 +1,37 @@
#include <cwchar> // for mbstate_t
#include <locale>
// give the character length for a given named locale
std::size_t char_length(std::string const& text, char const* locale_name)
{
// locales work on pointers; get length and data from string and
// then don't touch the original string any more, to avoid
// invalidating the data pointer
std::size_t len = text.length();
char const* input = text.data();
// get the named locale
std::locale loc(locale_name);
// get the conversion facet of the locale
typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt_type;
cvt_type const& cvt = std::use_facet<cvt_type>(loc);
// allocate buffer for conversion destination
std::size_t bufsize = cvt.max_length()*len;
wchar_t* destbuf = new wchar_t[bufsize];
wchar_t* dest_end;
// do the conversion
mbstate_t state = mbstate_t();
cvt.in(state, input, input+len, input, destbuf, destbuf+bufsize, dest_end);
// determine the length of the converted sequence
std::size_t length = dest_end - destbuf;
// get rid of the buffer
delete[] destbuf;
// return the result
return length;
}

View file

@ -0,0 +1,10 @@
#include <iostream>
int main()
{
// Tür (German for door) in UTF8
std::cout << char_length("\x54\xc3\xbc\x72", "de_DE.utf8") << "\n"; // outputs 3
// Tür in ISO-8859-1
std::cout << char_length("\x54\xfc\x72", "de_DE") << "\n"; // outputs 3
}

View file

@ -0,0 +1,2 @@
string s = "Hello, world!";
int characterLength = s.Length;

View file

@ -0,0 +1,4 @@
using System.Text;
string s = "Hello, world!";
int byteLength = Encoding.Unicode.GetByteCount(s);

View file

@ -0,0 +1 @@
int utf8ByteLength = Encoding.UTF8.GetByteCount(s);

View file

@ -0,0 +1,9 @@
#include <string.h>
int main(void)
{
const char *string = "Hello, world!";
size_t length = strlen(string);
return 0;
}

View file

@ -0,0 +1,10 @@
int main(void)
{
const char *string = "Hello, world!";
size_t length = 0;
const char *p = string;
while (*p++ != '\0') length++;
return 0;
}

View file

@ -0,0 +1,9 @@
#include <stdlib.h>
int main(void)
{
char s[] = "Hello, world!";
size_t length = sizeof s - 1;
return 0;
}

View file

@ -0,0 +1,14 @@
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t *s = L"\x304A\x306F\x3088\x3046"; /* Japanese hiragana ohayou */
size_t length;
length = wcslen(s);
printf("Length in characters = %d\n", length);
printf("Length in bytes = %d\n", sizeof(s) * sizeof(wchar_t));
return 0;
}

View file

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_CTYPE, "");
char moose[] = "møøse";
printf("bytes: %d\n", sizeof(moose) - 1);
printf("chars: %d\n", (int)mbstowcs(0, moose, 0));
return 0;
}

View file

@ -0,0 +1 @@
FUNCTION BYTE-LENGTH(str)

View file

@ -0,0 +1 @@
LENGTH OF str

View file

@ -0,0 +1 @@
FUNCTION LENGTH-AN(str)

View file

@ -0,0 +1 @@
FUNCTION LENGTH(str)

View file

@ -0,0 +1,6 @@
import StdEnv
strlen :: String -> Int
strlen string = size string
Start = strlen "Hello, world!"

View file

@ -0,0 +1,8 @@
(def utf-8-octet-length #(-> % (.getBytes "UTF-8") count))
(map utf-8-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (7 28 14)
(def utf-16-octet-length (comp (partial * 2) count))
(map utf-16-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (10 28 18)
(def code-unit-length count)
(map code-unit-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 14 9)

View file

@ -0,0 +1,2 @@
(def character-length #(.codePointCount % 0 (count %)))
(map character-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 9)

View file

@ -0,0 +1,8 @@
(def grapheme-length
#(->> (doto (java.text.BreakIterator/getCharacterInstance)
(.setText %))
(partial (memfn next))
repeatedly
(take-while (partial not= java.text.BreakIterator/DONE))
count))
(map grapheme-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 4)

View file

@ -0,0 +1,6 @@
<cfoutput>
<cfset str = "Hello World">
<cfset j = createObject("java","java.lang.String").init(str)>
<cfset t = j.getBytes()>
<p>#arrayLen(t)#</p>
</cfoutput>

View file

@ -0,0 +1 @@
#len("Hello World")#

View file

@ -0,0 +1,2 @@
10 INPUT A$
20 PRINT LEN(A$)

View file

@ -0,0 +1 @@
(length (sb-ext:string-to-octets "Hello Wørld"))

View file

@ -0,0 +1 @@
(length "Hello World")

View file

@ -0,0 +1,14 @@
MODULE TestLen;
IMPORT Out;
PROCEDURE DoCharLength*;
VAR s: ARRAY 16 OF CHAR; len: INTEGER;
BEGIN
s := "møøse";
len := LEN(s$);
Out.String("s: "); Out.String(s); Out.Ln;
Out.String("Length of characters: "); Out.Int(len, 0); Out.Ln
END DoCharLength;
END TestLen.

View file

@ -0,0 +1,15 @@
MODULE TestLen;
IMPORT Out;
PROCEDURE DoByteLength*;
VAR s: ARRAY 16 OF CHAR; len, v: INTEGER;
BEGIN
s := "møøse";
len := LEN(s$);
v := SIZE(CHAR) * len;
Out.String("s: "); Out.String(s); Out.Ln;
Out.String("Length of characters in bytes: "); Out.Int(v, 0); Out.Ln
END DoByteLength;
END TestLen.

View file

@ -0,0 +1 @@
"J̲o̲s̲é̲".bytesize

View file

@ -0,0 +1 @@
"J̲o̲s̲é̲".chars.length

View file

@ -0,0 +1,31 @@
import std.stdio;
void showByteLen(T)(T[] str) {
writefln("Byte length: %2d - %(%02x%)",
str.length * T.sizeof, cast(ubyte[])str);
}
void main() {
string s1a = "møøse"; // UTF-8
showByteLen(s1a);
wstring s1b = "møøse"; // UTF-16
showByteLen(s1b);
dstring s1c = "møøse"; // UTF-32
showByteLen(s1c);
writeln();
string s2a = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showByteLen(s2a);
wstring s2b = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showByteLen(s2b);
dstring s2c = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showByteLen(s2c);
writeln();
string s3a = "J̲o̲s̲é̲";
showByteLen(s3a);
wstring s3b = "J̲o̲s̲é̲";
showByteLen(s3b);
dstring s3c = "J̲o̲s̲é̲";
showByteLen(s3c);
}

View file

@ -0,0 +1,31 @@
import std.stdio, std.range, std.conv;
void showCodePointsLen(T)(T[] str) {
writefln("Character length: %2d - %(%x %)",
str.walkLength(), cast(uint[])to!(dchar[])(str));
}
void main() {
string s1a = "møøse"; // UTF-8
showCodePointsLen(s1a);
wstring s1b = "møøse"; // UTF-16
showCodePointsLen(s1b);
dstring s1c = "møøse"; // UTF-32
showCodePointsLen(s1c);
writeln();
string s2a = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showCodePointsLen(s2a);
wstring s2b = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showCodePointsLen(s2b);
dstring s2c = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
showCodePointsLen(s2c);
writeln();
string s3a = "J̲o̲s̲é̲";
showCodePointsLen(s3a);
wstring s3b = "J̲o̲s̲é̲";
showCodePointsLen(s3b);
dstring s3c = "J̲o̲s̲é̲";
showCodePointsLen(s3c);
}

View file

@ -0,0 +1 @@
sizeOf("foo")

View file

@ -0,0 +1,3 @@
[256 / d 0<L 1 + ] sL
22405534230753963835153736737 d P A P
lL x f

View file

@ -0,0 +1 @@
[abcde]Zp

View file

@ -0,0 +1 @@
"Hello World".Length()

View file

@ -0,0 +1 @@
"Hello World".size()

View file

@ -0,0 +1,4 @@
text moose = "møøse"
text unicode = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
text jose = "J" + 0U0332 + "o" + 0U0332 + "s" + 0U0332 + "e" + 0U0301 + 0U0332
text emoji = "𠇰😈🎶🔥é-"

View file

@ -0,0 +1,4 @@
writeLine((blob!moose).length)
writeLine((blob!unicode).length)
writeLine((blob!jose).length)
writeLine((blob!emoji).length)

View file

@ -0,0 +1,4 @@
writeLine(moose.codePointsLength)
writeLine(unicode.codePointsLength)
writeLine(jose.codePointsLength)
writeLine(emoji.codePointsLength)

View file

@ -0,0 +1,4 @@
writeLine(moose.graphemesLength)
writeLine(unicode.graphemesLength)
writeLine(jose.graphemesLength)
writeLine(emoji.graphemesLength)

View file

@ -0,0 +1,8 @@
# 5
print len "møøse"
# 7
print len "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
# 8
print len "J̲o̲s̲é̲"
# 1
print len "😀"

View file

@ -0,0 +1,11 @@
import extensions;
public program()
{
var s := "Hello, world!"; // UTF-8 literal
var ws := "Привет мир!"w; // UTF-16 literal
var s_length := s.Length; // Number of UTF-8 characters
var ws_length := ws.Length; // Number of UTF-16 characters
var u_length := ws.toArray().Length; //Number of UTF-32 characters
}

View file

@ -0,0 +1,10 @@
import extensions;
public program()
{
var s := "Hello, world!"; // UTF-8 literal
var ws := "Привет мир!"w; // UTF-16 literal
var s_byte_length := s.toByteArray().Length; // Number of bytes
var ws_byte_length := ws.toByteArray().Length; // Number of bytes
}

View file

@ -0,0 +1,3 @@
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
byte_size(name)
# => 14

View file

@ -0,0 +1,3 @@
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
Enum.count(String.codepoints(name))
# => 9

View file

@ -0,0 +1,3 @@
name = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}"
String.length(name)
# => 4

View file

@ -0,0 +1,2 @@
(length "hello")
;; => 5

View file

@ -0,0 +1,2 @@
(string-bytes "\u1D518\u1D52B\u1D526")
;; => 12

View file

@ -0,0 +1,7 @@
(let ((str (apply 'string
(mapcar (lambda (c) (decode-char 'ucs c))
'(#x1112 #x1161 #x11ab #x1100 #x1173 #x11af)))))
(list (length str)
(string-bytes str)
(string-width str)))
;; => (6 18 4) ;; in emacs 23 up

View file

@ -0,0 +1 @@
print(1,length("Hello World"))

View file

@ -0,0 +1,2 @@
open System.Text
let byte_length str = Encoding.UTF8.GetByteCount(str)

View file

@ -0,0 +1 @@
"Hello, World".Length

Some files were not shown because too many files have changed in this diff Show more