September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
2
Task/String-length/BASIC/string-length-4.basic
Normal file
2
Task/String-length/BASIC/string-length-4.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
100 INPUT PROMPT "String: ":TX$
|
||||
110 PRINT LEN(TX$)
|
||||
4
Task/String-length/Bracmat/string-length-4.bracmat
Normal file
4
Task/String-length/Bracmat/string-length-4.bracmat
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(CharacterLength=
|
||||
length
|
||||
. vap$((=.!arg).!arg):? [?length&!length
|
||||
);
|
||||
3
Task/String-length/Dc/string-length-1.dc
Normal file
3
Task/String-length/Dc/string-length-1.dc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[256 / d 0<L 1 + ] sL
|
||||
22405534230753963835153736737 d P A P
|
||||
lL x f
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
program =
|
||||
[
|
||||
var s := "Hello, world!". // UTF-8 literal
|
||||
var ws := "Привет мир!"w. // UTF-16 literal
|
||||
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
|
||||
].
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
program =
|
||||
[
|
||||
var s := "Hello, world!". // UTF-8 literal
|
||||
var ws := "Привет мир!"w. // UTF-16 literal
|
||||
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
|
||||
].
|
||||
var s_byte_length := s.toByteArray().Length; // Number of bytes
|
||||
var ws_byte_length := ws.toByteArray().Length; // Number of bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,6 @@
|
|||
String.length "møøse"
|
||||
UTF8.length "møøse"
|
||||
open CamomileLibrary
|
||||
|
||||
let () =
|
||||
Printf.printf " %d\n" (String.length "møøse");
|
||||
Printf.printf " %d\n" (UTF8.length "møøse");
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
constant s = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
?length(s)
|
||||
?length(utf8_to_utf32(s))
|
||||
|
|
|
|||
3
Task/String-length/Robotic/string-length.robotic
Normal file
3
Task/String-length/Robotic/string-length.robotic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
set "$local1" to "Hello world!"
|
||||
* "String length: &$local1.length&"
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Module ByteLength
|
||||
Function GetByteLength(s As String, encoding As Text.Encoding) As Integer
|
||||
Return encoding.GetByteCount(s)
|
||||
End Function
|
||||
End Module
|
||||
20
Task/String-length/Visual-Basic-.NET/string-length-2.visual
Normal file
20
Task/String-length/Visual-Basic-.NET/string-length-2.visual
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Module CharacterLength
|
||||
Function GetUTF16CodeUnitsLength(s As String) As Integer
|
||||
Return s.Length
|
||||
End Function
|
||||
|
||||
Private Function GetUTF16SurrogatePairCount(s As String) As Integer
|
||||
GetUTF16SurrogatePairCount = 0
|
||||
For i = 1 To s.Length - 1
|
||||
If Char.IsSurrogatePair(s(i - 1), s(i)) Then GetUTF16SurrogatePairCount += 1
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function GetCharacterLength_FromUTF16(s As String) As Integer
|
||||
Return GetUTF16CodeUnitsLength(s) - GetUTF16SurrogatePairCount(s)
|
||||
End Function
|
||||
|
||||
Function GetCharacterLength_FromUTF32(s As String) As Integer
|
||||
Return GetByteLength(s, Text.Encoding.UTF32) \ 4
|
||||
End Function
|
||||
End Module
|
||||
13
Task/String-length/Visual-Basic-.NET/string-length-3.visual
Normal file
13
Task/String-length/Visual-Basic-.NET/string-length-3.visual
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Module GraphemeLength
|
||||
' Wraps an IEnumerator, allowing it to be used as an IEnumerable.
|
||||
Private Iterator Function AsEnumerable(enumerator As IEnumerator) As IEnumerable
|
||||
Do While enumerator.MoveNext()
|
||||
Yield enumerator.Current
|
||||
Loop
|
||||
End Function
|
||||
|
||||
Function GraphemeCount(s As String) As Integer
|
||||
Dim elements = Globalization.StringInfo.GetTextElementEnumerator(s)
|
||||
Return AsEnumerable(elements).OfType(Of String).Count()
|
||||
End Function
|
||||
End Module
|
||||
39
Task/String-length/Visual-Basic-.NET/string-length-4.visual
Normal file
39
Task/String-length/Visual-Basic-.NET/string-length-4.visual
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#Const PRINT_TESTCASE = True
|
||||
|
||||
Module Program
|
||||
ReadOnly TestCases As String() =
|
||||
{
|
||||
"Hello, world!",
|
||||
"møøse",
|
||||
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢", ' String normalization of the file makes the e and diacritic in é̲ one character, so use VB's char "escapes"
|
||||
$"J{ChrW(&H332)}o{ChrW(&H332)}s{ChrW(&H332)}e{ChrW(&H301)}{ChrW(&H332)}"
|
||||
}
|
||||
|
||||
Sub Main()
|
||||
Const INDENT = " "
|
||||
Console.OutputEncoding = Text.Encoding.Unicode
|
||||
|
||||
Dim writeResult = Sub(s As String, result As Integer) Console.WriteLine("{0}{1,-20}{2}", INDENT, s, result)
|
||||
|
||||
For i = 0 To TestCases.Length - 1
|
||||
Dim c = TestCases(i)
|
||||
|
||||
Console.Write("Test case " & i)
|
||||
#If PRINT_TESTCASE Then
|
||||
Console.WriteLine(": " & c)
|
||||
#Else
|
||||
Console.WriteLine()
|
||||
#End If
|
||||
writeResult("graphemes", GraphemeCount(c))
|
||||
writeResult("UTF-16 units", GetUTF16CodeUnitsLength(c))
|
||||
writeResult("Cd pts from UTF-16", GetCharacterLength_FromUTF16(c))
|
||||
writeResult("Cd pts from UTF-32", GetCharacterLength_FromUTF32(c))
|
||||
Console.WriteLine()
|
||||
writeResult("bytes (UTF-8)", GetByteLength(c, Text.Encoding.UTF8))
|
||||
writeResult("bytes (UTF-16)", GetByteLength(c, Text.Encoding.Unicode))
|
||||
writeResult("bytes (UTF-32)", GetByteLength(c, Text.Encoding.UTF32))
|
||||
Console.WriteLine()
|
||||
Next
|
||||
|
||||
End Sub
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue