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,6 @@
---
category:
- String manipulation
- Syntax elements
from: http://rosettacode.org/wiki/Literals/String
note: Basic language learning

View file

@ -0,0 +1,19 @@
;Task:
Show literal specification of characters and strings.
If supported, show how the following work:
:*   ''verbatim strings''   (quotes where escape sequences are quoted literally)
:*   ''here-strings''  
<br>
Also, discuss which quotes expand variables.
;Related tasks:
* &nbsp; [[Special characters]]
* &nbsp; [[Here document]]
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1 @@
V c = Char(a)

View file

@ -0,0 +1 @@
"foo\nbar"

View file

@ -0,0 +1,2 @@
foo
bar

View file

@ -0,0 +1 @@
'dont // the same as "dont"

View file

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

View file

@ -0,0 +1,2 @@
db "Hello World"
db $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64

View file

@ -0,0 +1,2 @@
LDA #'A' ;load ascii code of "A" into the accumulator.
LDA 'A' ;load the byte stored at memory address 0x41 into the accumulator.

View file

@ -0,0 +1 @@
db "Hello World",13,10,0

View file

@ -0,0 +1,23 @@
PrintString:
lda (StringPtr),y
beq Terminated
cmp #'\' ; a single ascii character is specified in single quotes.
beq HandleSpecialChars
jsr PrintChar ;unimplemented print routine
iny ;next character
jmp PrintString ;back to top
Terminated:
rts ;exit
HandleSpecialChars:
iny ;next char
lda (StringPtr),y
cmp #'n'
beq NextLine ;unimplemented new line routine, it ends in "JMP DoneSpecialChar."
;Typically this would reset the x cursor and increment the y cursor, which are software variables that
;get converted to a VRAM address in some other routine.
DoneSpecialChar:
iny
jmp PrintString ;jump back to top. Notice that neither the backslash nor the character after it were actually printed.

View file

@ -0,0 +1,2 @@
DC.B "Hello World",0
EVEN

View file

@ -0,0 +1,5 @@
DC.B "Hello World",0
EVEN
DC.B $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64,$00
EVEN

View file

@ -0,0 +1,3 @@
MOVE.L #'SEGA',D0 ;load the string "SEGA" into D0
MOVE.L '0000',D0 ;load the 32-bit value at address 0x00303030 (the most significant byte is always treated as zero,
;because the 68000 only has a 24-bit address space.

View file

@ -0,0 +1 @@
CHAR charx = "z";

View file

@ -0,0 +1,6 @@
INT pages=100, lines=25, characters=80;
FILE bookf; FLEX[pages]FLEX[lines]FLEX[characters]CHAR book;
associate(bookf, book);
# following putf inserts the string " Line 4 indented 5" on page 3 #
putf(bookf, $3p"Page 3"4l5x"Line 4 indented 5"$)

View file

@ -0,0 +1,3 @@
[]CHAR charxyz = "xyz";
STRING stringxyz = "xyz";
FORMAT twonewlines = $ll$, threenewpages=$ppp$, fourbackspaces=$bbbb$;

View file

@ -0,0 +1,2 @@
.PR QUOTE .PR
[]'CHAR' CHARXYZ = "XYZ";

View file

@ -0,0 +1 @@
MODE STRING = FLEX[1:0]CHAR;

View file

@ -0,0 +1 @@
BYTES bytesabc = bytes pack("abc");

View file

@ -0,0 +1 @@
STRING stringquote = """I'll be back."" - The Terminator";

View file

@ -0,0 +1,3 @@
STRING linexyz := "line X;" +
"line Y;" +
"line Z;";

View file

@ -0,0 +1,2 @@
FILE linef; STRING line;
associate(linef, line);

View file

@ -0,0 +1,3 @@
FORMAT my_symbol = $"SYMBOL"$;
FORMAT foo = $"prefix_"f(my_symbol)"_suffix"$;
putf(linef ,foo);

View file

@ -0,0 +1,20 @@
begin
% String literals are enclosed in double-quotes in Algol W. %
% There isn't a separate character type but strings of lenghth one can %
% be used instead. %
% There are no escaping conventions used in string literals, except that %
% in order to have a double-quote character in a string, two double %
% quotes must be used. %
% Examples: %
% write a single character %
write( "a" );
% write a double-quote character %
write( """" );
% write a multi-character string - note the "\" is not an escape %
% and a\nb will appear on the output, not a and b on separate lines %
write( "a\nb" );
end.

View file

@ -0,0 +1,78 @@
/* ARM assembly Raspberry PI */
/* program stringsEx.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/* Initialized data */
.data
szMessString: .asciz "String with final zero \n"
szMessString1: .string "Other string with final zero \n"
sString: .ascii "String without final zero"
.byte 0 @ add final zero for display
sLineSpaces: .byte '>'
.fill 10,1,' ' @ 10 spaces
.asciz "<\n" @ add <, CR and final zero for display
sSpaces1: .space 10,' ' @ other 10 spaces
.byte 0 @ add final zero for display
sCharA: .space 10,'A' @ curious !! 10 A with space instruction
.asciz "\n" @ add CR and final zero for display
cChar1: .byte 'A' @ character A
cChar2: .byte 0x41 @ character A
szCarriageReturn: .asciz "\n"
/* UnInitialized data */
.bss
/* code section */
.text
.global main
main:
ldr r0,iAdrszMessString
bl affichageMess @ display message
ldr r0,iAdrszMessString1
bl affichageMess
ldr r0,iAdrsString
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrsLineSpaces
bl affichageMess
ldr r0,iAdrsCharA
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform system call
iAdrszMessString: .int szMessString
iAdrszMessString1: .int szMessString1
iAdrsString: .int sString
iAdrsLineSpaces: .int sLineSpaces
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsCharA: .int sCharA
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registers
mov r2,#0 @ counter length */
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call system
pop {r0,r1,r2,r7,lr} @ restaur registers
bx lr @ return

View file

@ -0,0 +1,6 @@
c = "x"
str= "hello"
s1 = "abcd" # simple string
s2 = "ab\"cd" # string containing a double quote, escaped with backslash
print s1
print s2

View file

@ -0,0 +1,2 @@
$ awk 'BEGIN{c="x"; s="hello";s1 = "abcd"; s2 = "ab\"cd"; s=s c; print s; print s1; print s2}'
hellox

View file

@ -0,0 +1 @@
ch : character := 'a';

View file

@ -0,0 +1,2 @@
msg : string := "hello world";
empty : string := ""; -- an empty string

View file

@ -0,0 +1,2 @@
integer c;
c = 'z';

View file

@ -0,0 +1,2 @@
text s;
s = "z";

View file

@ -0,0 +1,4 @@
M$ = CHR$(13) : Q$ = CHR$(34)
A$ = "THERE ARE" + M$
A$ = A$ + "NO " + Q$ + "HERE" + Q$ + " STRINGS."
? A$

View file

@ -0,0 +1,24 @@
str: "Hello world"
print [str "->" type str]
fullLineStr: « This is a full-line string
print [fullLineStr "->" type fullLineStr]
multiline: {
This
is a multi-line
string
}
print [multiline "->" type multiline]
verbatim: {:
This is
a verbatim
multi-line
string
:}
print [verbatim "->" type verbatim]

View file

@ -0,0 +1,13 @@
"c" ; character
"text" ; string
hereString = ; with interpolation of %variables%
(
"<>"
the time is %A_Now%
\!
)
hereString2 = ; with same line comments allowed, without interpolation of variables
(Comments %
literal %A_Now% ; no interpolation here
)

View file

@ -0,0 +1 @@
'A'

View file

@ -0,0 +1 @@
"ABC"

View file

@ -0,0 +1,4 @@
10 LET Q$=CHR$(34): REM DOUBLEQUOTES
20 LET D$=Q$+Q$: REM A PAIR OF DOUBLEQUOTES
30 LET S$=Q$+"THIS IS A QUOTED STRING"+Q$
40 PRINT Q$;"HELLO";Q$:REM ADD QUOTES DURING OUTPUT

View file

@ -0,0 +1,5 @@
DIM c AS STRING * 1, s AS STRING
c = "char" 'everything after the first character is silently discarded
s = "string"
PRINT CHR$(34); s; " data "; c; CHR$(34)

View file

@ -0,0 +1,3 @@
print "Hello, World."
print chr(34); "Hello, World." & chr(34)
print "Tom said," + "'The fox ran away.'"

View file

@ -0,0 +1 @@
PRINT "This is a ""quoted string"""

View file

@ -0,0 +1 @@
"gnirts">:#,_@

View file

@ -0,0 +1,3 @@
auto strA = R"(this is
a newline-separated
raw string)";

View file

@ -0,0 +1,4 @@
string path = @"C:\Windows\System32";
string multiline = @"Line 1.
Line 2.
Line 3.";

View file

@ -0,0 +1 @@
char ch = 'z';

View file

@ -0,0 +1 @@
char str[] = "z";

View file

@ -0,0 +1,3 @@
char lines[] = "line 1\n"
"line 2\n"
"line 3\n";

View file

@ -0,0 +1 @@
#define FOO "prefix_"##MY_SYMBOL##"_suffix"

View file

@ -0,0 +1,2 @@
"This is a valid string."
'As is this.'

View file

@ -0,0 +1,2 @@
X"00" *> Null character
X"48656C6C6F21" *> "Hello!"

View file

@ -0,0 +1,6 @@
HIGH-VALUE HIGH-VALUES *> Equivalent to (a string of) X"FF".
LOW-VALUE LOW-VALUES *> " " X"00".
NULL *> " " X"00".
QUOTE QUOTES *> " " double-quote character.
SPACE SPACES *> " " space.
ZERO ZEROS ZEROES *> " " zero.

View file

@ -0,0 +1,3 @@
[\h \e \l \l \o] ; a vector of characters
\uXXXX ; where XXXX is some hex Unicode code point
\\ ; the backslash character literal

View file

@ -0,0 +1,6 @@
\space
\newline
\tab
\formfeed
\return
\backspace

View file

@ -0,0 +1 @@
"hello world\r\n"

View file

@ -0,0 +1,3 @@
(let ((colon #\:)
(str "http://www.rosettacode.com/"))
(format t "colon found at position ~d~%" (position colon str)))

View file

@ -0,0 +1 @@
char c = 'a';

View file

@ -0,0 +1,4 @@
auto str = "hello"; // UTF-8
auto str2 = "hello"c; // UTF-8
auto str3 = "hello"w; // UTF-16
auto str4 = "hello"d; // UTF-32

View file

@ -0,0 +1,2 @@
auto str = `"Hello," he said.`;
auto str2 = r"\n is slash-n";

View file

@ -0,0 +1,4 @@
// Any character is allowed after the first quote;
// the string ends with that same character followed
// by a quote.
auto str = q"$"Hello?" he enquired.$";

View file

@ -0,0 +1,5 @@
// If you include a newline, you get a heredoc string:
auto otherStr = q"EOS
This is part of the string.
So is this.
EOS";

View file

@ -0,0 +1,4 @@
// The contents of a token string must be valid code fragments.
auto str = q{int i = 5;};
// The contents here isn't a legal token in D, so it's an error:
auto illegal = q{@?};

View file

@ -0,0 +1,2 @@
// assigns value 'hello' to str
auto str = x"68 65 6c 6c 6f";

View file

@ -0,0 +1,3 @@
const s1 := 'quoted "word" in string';
const s2 := "quoted ""word"" in string"; // sames as s1, shows the doubling of the delimiter
const s2 := 'first line'#13#10'second line'; // CR+LF in the middle

View file

@ -0,0 +1,8 @@
var
lChar: Char;
lLine: string;
lMultiLine: string;
begin
lChar := 'a';
lLine := 'some text';
lMultiLine := 'some text' + #13#10 + 'on two lines';

View file

@ -0,0 +1,2 @@
let c = '\u0020' //a character
let str = "A string\non several lines!\sAnd you can incorporate expressions: \(c)!"

View file

@ -0,0 +1,3 @@
let long_str = <[first line
second line
third line]>

View file

@ -0,0 +1,4 @@
'T' # character
"The quick brown fox" # string
`The $kind brown fox` # "simple" quasiliteral
term`the($adjectives*, fox)` # "term" quasiliteral

View file

@ -0,0 +1,5 @@
? if ("<abc,def>" =~ `<@a,@b>`) { [a, b] } else { null }
# value: ["abc", "def"]
? if (" >abc, def< " =~ rx`\W*(@a\w+)\W+(@b\w+)\W*`) { [a, b] } else { null }
# value: ["abc", "def"]

View file

@ -0,0 +1,2 @@
print "EasyLang"
print "简"

View file

@ -0,0 +1 @@
c = 'c'

View file

@ -0,0 +1 @@
str = "Hello, world!"

View file

@ -0,0 +1,2 @@
c = '\t'
str = "first line\nsecond line\nthird line"

View file

@ -0,0 +1,2 @@
vs = <[This is a
verbatim string]>

View file

@ -0,0 +1,5 @@
var c := $65; // character
var s := "some text"; // UTF-8 literal
var w := "some wide text"w; // UTF-16 literal
var s2 := "text with ""quotes"" and
two lines";

View file

@ -0,0 +1,3 @@
IO.puts "Begin String \n============"
str = "string"
str |> is_binary # true

View file

@ -0,0 +1 @@
str |> String.codepoints

View file

@ -0,0 +1 @@
str <> <<0>>

View file

@ -0,0 +1,3 @@
?a # 97
Code.eval_string("?b") # 98
Code.eval_string("?ł") # 322

View file

@ -0,0 +1,4 @@
IO.inspect "Begin Char List \n============="
[115, 116, 114, 105, 110, 103]
ch = "hi"
'string #{ch}'

View file

@ -0,0 +1 @@
'string #{ch}'++[0]

View file

@ -0,0 +1 @@
"This is a string."

View file

@ -0,0 +1,2 @@
?z ;=> 122
?\n ;=> 10

View file

@ -0,0 +1,2 @@
"This is a string".
[$T,$h,$i,$s,$ ,$a,$ ,$s,$t,$r,$i,$n,$g,$,,$ ,$t,$o,$o].

View file

@ -0,0 +1 @@
97 == $a. % => true

View file

@ -0,0 +1 @@
"\"The quick brown fox jumps over the lazy dog.\"".

View file

@ -0,0 +1,7 @@
let n= 'N'
let i="Name=\"Nigel Galloway\"\n"
let g= @"Name=""Nigel Galloway""\n"
let e="Nigel
Galloway"
let l= """Name="Nigel Galloway"\n"""
printfn "%c\n%s\n%s\n%s\n%s" n i g e l

View file

@ -0,0 +1 @@
CHAR: a

View file

@ -0,0 +1,7 @@
USE: multiline
STRING: random-stuff
ABC
123
"x y z
;
random-stuff print

View file

@ -0,0 +1,15 @@
USING: interpolate locals namespaces ;
"Sally" "name" set
"bicycle"
"home"
[let
"crying" :> a
[I ${name} crashed her ${1}. Her ${1} broke.
${name} ran ${} ${a}.
I]
]

View file

@ -0,0 +1,5 @@
CHAR: x ! 120
CHAR: \u000032 ! 50
CHAR: \u{exclamation-mark} ! 33
CHAR: exclamation-mark ! 33
CHAR: ugaritic-letter-samka ! 66450

View file

@ -0,0 +1 @@
"Hello, world!"

View file

@ -0,0 +1 @@
"Hello, world!" { } like ! { 72 101 108 108 111 44 32 119 111 114 108 100 33 }

View file

@ -0,0 +1 @@
"Line one\nLine two" print

View file

@ -0,0 +1 @@
"\"Hello,\" she said." print

View file

@ -0,0 +1,3 @@
"2\u{superscript-two} = 4
2\u{superscript-three} = 8
2\u{superscript-four} = 16" print

View file

@ -0,0 +1,4 @@
USE: multiline
[[ escape codes \t are literal \\ in here
but newlines \u{plus-minus-sign} are still
inserted " for each line the string \" spans.]] print

View file

@ -0,0 +1,8 @@
USE: multiline
HEREDOC: END
Everything between the line above
and the final line (a user-defined token)
is parsed into a string where whitespace
is significant.
END
print

View file

@ -0,0 +1,2 @@
char c emit
s" string" type

View file

@ -0,0 +1,3 @@
: main
[char] c emit
s" string" type ;

View file

@ -0,0 +1,2 @@
'c emit
s\" hello\nthere!"

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