BeginComment:
This program demonstrates basic string functions.

Copyright © 2020 Richard Lesh.  All rights reserved.
EndComment

Pragma: UseUnicode

BeginProgram: Strings2

BeginMain:
	ScalarDecl: const <string> alphabet = "abcdefghijklmnopqrstuvwxyzabc"
	ScalarDecl: const <string> greekAlphabet = "αβγδεζηθικλμνξοπρσςτυφχψωαβγ"
	ScalarDecl: const <string> emoji = "😃😇🥰🤪🤑😴🤒🥵🥶🤯🥳😎😥😱😡🤬💀👽🤖😺🙈🙉🙊😃😇🥰"

	PrintLine: "Length: ", strlen(alphabet)
	PrintLine: "charAt(17): ", char_at(alphabet, 17)
	PrintLine: "codePointAt(17): ", codepoint_at(alphabet, 17)
	PrintLine: "substr(23, 26): ", substr(alphabet, 23, 26)
	PrintLine: "prefix(6): ", prefix(alphabet, 6)
	PrintLine: "right_tail(6): ", right_tail(alphabet, 6)
	PrintLine: "suffix(6): ", suffix(alphabet, 6)
	PrintLine: "find(\'def\'): ", find(alphabet, "def")
	PrintLine: "find(\'def\') is not found: ", (find(alphabet, "def") == STRING_NOT_FOUND)
	PrintLine: "find(\'bug\'): ", find(alphabet, "bug")
	PrintLine: "find(\'bug\') is not found: ", (find(alphabet, "bug") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'abc\'): ", rfind(alphabet, "abc")
	PrintLine: "rfind(\'abc\') is not found: ", (rfind(alphabet, "abc") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'bug\'): ", rfind(alphabet, "bug")
	PrintLine: "rfind(\'bug\') is not found: ", (rfind(alphabet, "bug") == STRING_NOT_FOUND)

	PrintLine: "Length: ", strlen(greekAlphabet)
	PrintLine: "charAt(17): ", char_at(greekAlphabet, 17)
	PrintLine: "codePointAt(17): ", codepoint_at(greekAlphabet, 17)
	PrintLine: "substr(23, 26): ", substr(greekAlphabet, 23, 26)
	PrintLine: "prefix(6): ", prefix(greekAlphabet, 6)
	PrintLine: "right_tail(6): ", right_tail(greekAlphabet, 6)
	PrintLine: "suffix(6): ", suffix(greekAlphabet, 6)
	PrintLine: "find(\'δεζ\'): ", find(greekAlphabet, "δεζ")
	PrintLine: "find(\'δεζ\') is not found: ", (find(greekAlphabet, "δεζ") == STRING_NOT_FOUND)
	PrintLine: "find(\'bug\'): ", find(greekAlphabet, "bug")
	PrintLine: "find(\'bug\') is not found: ", (find(greekAlphabet, "bug") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'αβγ\'): ", rfind(greekAlphabet, "αβγ")
	PrintLine: "rfind(\'αβγ\') is not found: ", (rfind(greekAlphabet, "αβγ") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'bug\'): ", rfind(greekAlphabet, "bug")
	PrintLine: "rfind(\'bug\') is not found: ", (rfind(greekAlphabet, "bug") == STRING_NOT_FOUND)

BeginEval: language =~ m/java|js/
BeginComment:
Because strings are represented using UTF-16 it takes two characters to
represent one codepoint for these emoji.  So lengths and positions are twice
what we normally would expect when dealing with Unicode characters.  So the
standard string functions basically only work correctly with chraracters from
the BMP.  Use the functions from Utils module to work correctly with all 
Unicode characters.
EndComment
EndEval
	PrintLine: "Length: ", strlen(emoji)
	PrintLine: "charAt(16): ", char_at(emoji, 16)
	PrintLine: "codePointAt(16): ", codepoint_at(emoji, 16)
	PrintLine: "substr(20, 24): ", substr(emoji, 20, 24)
	PrintLine: "prefix(6): ", prefix(emoji, 6)
	PrintLine: "right_tail(6): ", right_tail(emoji, 6)
	PrintLine: "suffix(6): ", suffix(emoji, 6)
	PrintLine: "find(\'😱😡🤬\'): ", find(emoji, "😱😡🤬")
	PrintLine: "find(\'😱😡🤬\') is not found: ", (find(emoji, "😱😡🤬") == STRING_NOT_FOUND)
	PrintLine: "find(\'bug\'): ", find(emoji, "bug")
	PrintLine: "find(\'bug\') is not found: ", (find(emoji, "bug") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'😃😇🥰\'): ", rfind(emoji, "😃😇🥰")
	PrintLine: "rfind(\'😃😇🥰\') is not found: ", (rfind(emoji, "😃😇🥰") == STRING_NOT_FOUND)
	PrintLine: "rfind(\'bug\'): ", rfind(emoji, "bug")
	PrintLine: "rfind(\'bug\') is not found: ", (rfind(emoji, "bug") == STRING_NOT_FOUND)
EndMain
EndProgram
