// //------------------ DOK FILE -------------------------------------------------- +Header strLib =pkg bios =title Strings =short immutable arrays of bytes =desc Strings are simply made of binary bytes. They are immutable. // // //------------------ PROTO ----------------------------------------------------- Str +Proto Str =type Str =mode type =pkg bios =impl native =link =desc In Minimacy, strings are simply an immutable array of bytes. It is possible to define a string in the Minimacy syntax. A string is always delimited with double quotes. As in many languages, the backslash is the escape character. The escape character allows to define a string with double quotes inside. "foo\"bar" It is also the way to define a string with a backslash inside. "foo\\bar" Other common escape sequences include \\n \\r \\t \\z There is also an escape sequence when you use the ascii code in decimal: > "foo\66ar" >-> "fooBar" However it is more convenient to use the hexadecimal code which is always 2 characters long: > "foo\$42ar" >-> "fooBar" // // //------------------ PROTO ----------------------------------------------------- intFromStr +Proto intFromStr =type fun Str -> Int =mode function =pkg bios =impl native =link =desc This function decodes a decimal representation of an integer. > intFromStr ("123") >-> Int: 123 (0x7B) It stops as soon as it reaches a character which is not a decimal digit. > intFromStr ("12W3") >-> Int: 12 (0xC) // +arg src =type Str =desc // +arg result =type Int =desc The decoded integer. // // //------------------ PROTO ----------------------------------------------------- strBuild +Proto strBuild =type fun a1 -> Str =mode function =pkg bios =impl native =link =desc This function creates a new string representation from any data. Basically it iterates through the data and make a string from each element. - a string is printed as it is - an integer or a float are printed in decimal - true or false are printed 'true' or 'false' - nil is not printed at all - members of a tuple, an array or a list are printed in their natural order > strBuild( [nil, "foo", 123, "/", 12.3, {"foo", "bar"}, 1::2::3::nil]) >-> Str: "foo123/12.3foobar123" The strJoin function is almost the same except it adds a separator between each printable element. // +arg data =type a1 =desc Any data // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- strConcat +Proto strConcat =type fun Str Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string, made by the concatenation of two strings p and q. > strConcat ("foo", "bar") >-> Str: "foobar" Strings p and q remain unchanged. // +arg p =type Str =desc A string // +arg q =type Str =desc Another string // +arg result =type Str =desc The concatenation. // // //------------------ PROTO ----------------------------------------------------- strCharPos +Proto strCharPos =type fun Str Int Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the position of a specific char code in the string src. It returns nil when the char code is not found. > strCharPos ("foobAr", 'A', 0) >-> Int: 4 (0x4) When the offset is negative, the search position is counted from the end of the string src. > strCharPos ("hello world", 'l', -5) >-> Int: 9 (0x9) // +arg src =type Str =desc A string // +arg code =type Int =desc A char code, from 0 to 255 // +arg offset =type Int =desc The position from which the search will start // +arg result =type Int =desc The first occurrence of the char code in the string src // // //------------------ PROTO ----------------------------------------------------- strCharPosRev +Proto strCharPosRev =type fun Str Int Int -> Int =mode function =pkg bios =impl native =link =desc This function is similar to strCharPos except it searches backwards. > strCharPosRev ("hello world", 'l', nil) >-> Int: 9 (0x9) // +arg src =type Str =desc A string // +arg code =type Int =desc A char code, from 0 to 255 // +arg offset =type Int =desc The position from which the backards search will start. A nil value means 'from the end of the string src' // +arg result =type Int =desc The last occurrence of the char code in the string src // // //------------------ PROTO ----------------------------------------------------- strCmp +Proto strCmp =type fun Str Str -> Int =mode function =pkg bios =impl native =link =desc This function returns the result of the comparison between two strings: - 0: p and q are equals - -1: p is before q in ascii order - 1: p is after q in ascii order > strCmp ("foo", "bar") >-> Int: 1 (0x1) Be aware that the ascii order is not exactly the alphabetical order. Uppercase are before lowercase. And the order is not only for alphanumerical values: '+' is before '-'. // +arg p =type Str =desc A string // +arg q =type Str =desc Another string // +arg result =type Int =desc 0, 1, or -1 // // //------------------ PROTO ----------------------------------------------------- strContains +Proto strContains =type fun Str Str -> Bool =mode function =pkg bios =impl mcy =link =desc This function returns true if the string src contains the substring sub. // +arg src =type Str =desc A string // +arg sub =type Str =desc A potential substring // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- strEndsWith +Proto strEndsWith =type fun Str Str -> Bool =mode function =pkg bios =impl mcy =link =desc This function returns true if the string src ends with the substring sub. // +arg src =type Str =desc A string // +arg sub =type Str =desc A potential substring // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- strGet +Proto strGet =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the byte value located at the position index in the string src. > strGet ("foobar", 4) >-> Int: 97 (0x61) When the index is negative it is counted from the end of the string src. > strGet ("foobar", -2) >-> Int: 97 (0x61) // +arg src =type Str =desc A string // +arg index =type Int =desc An integer // +arg result =type Int =desc An integer between 0 and 255, or nil // // //------------------ PROTO ----------------------------------------------------- strInt16Lsb +Proto strInt16Lsb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the LSB 16bits string representation of the number val. Knowing that 'A' and 'B' have ascii code 0x41 and 0x42: > strInt16Lsb (0x4142) >-> Str: "BA" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 2-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt16Msb +Proto strInt16Msb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the MSB 16bits string representation of the number val. Knowing that 'A' and 'B' have ascii code 0x41 and 0x42: > strInt16Msb (0x4142) >-> Str: "AB" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 2-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt24Lsb +Proto strInt24Lsb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the LSB 24bits string representation of the number val. Knowing that 'A', 'B' and 'C' have ascii code 0x41, 0x42 and 0x43: > strInt24Lsb (0x414243) >-> Str: "CBA" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 3-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt24Msb +Proto strInt24Msb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the MSB 24bits string representation of the number val. Knowing that 'A', 'B' and 'C' have ascii code 0x41, 0x42 and 0x43: > strInt24Msb (0x414243) >-> Str: "ABC" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 3-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt32Lsb +Proto strInt32Lsb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the LSB 32bits string representation of the number val. Knowing that 'A', 'B', 'C' and 'D' have ascii code 0x41, 0x42, 0x43 and 0x44: > strInt32Lsb (0x41424344) >-> Str: "DCBA" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 4-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt32Msb +Proto strInt32Msb =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the MSB 32bits string representation of the number val. Knowing that 'A', 'B', 'C' and 'D' have ascii code 0x41, 0x42, 0x43 and 0x44: > strInt32Msb (0x41424344) >-> Str: "ABCD" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 4-bytes string // // //------------------ PROTO ----------------------------------------------------- strInt8 +Proto strInt8 =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the 1-byte string representation of the number val. Knowing that 'A' has ascii code 0x41: > strInt8 (0x41) >-> Str: "A" // +arg val =type Int =desc An integer // +arg result =type Str =desc A 1-byte string // // //------------------ PROTO ----------------------------------------------------- strJoin +Proto strJoin =type fun Str a1 -> Str =mode function =pkg bios =impl native =link =desc This function creates a new string representation from any data. Basically it iterates through the data and make a string from each element, inserting the separator between each printable element. - a string is printed as it is - an integer or a float are printed in decimal - true or false are printed 'true' or 'false' - nil is not printed at all - members of a tuple, an array or a list are printed in their natural order > strJoin (" ", [nil, "foo", 123, "/", 12.3, {"foo", "bar"}, 1::2::3::nil]) >-> Str: "foo 123 / 12.3 foo bar 1 2 3" The strBuild function is almost the same but without the separator. // +arg separator =type Str =desc A string // +arg data =type a1 =desc Any data // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- strLeftBytes +Proto strLeftBytes =type fun Bytes Int -> Str =mode function =pkg bios =impl native =link =desc This function is similar to [[strLeft]], except it works on an array of bytes and returns a string. // +arg src =type Bytes =desc An array of bytes // +arg B =type Int =desc An integer // +arg result =type Str =desc The prefix // // //------------------ PROTO ----------------------------------------------------- strLeft +Proto strLeft =type fun Str Int -> Str =mode function =pkg bios =impl native =link =desc This function returns a prefix of the string src with at most length bytes. > strLeft ("foobar", 3) >-> Str: "foo" > strLeft ("foobar", 8) >-> Str: "foobar" > strLeft ("foobar", 0) >-> Str: nil When length is negative it is counted from the end of the string src > strLeft ("foobar", -1) >-> Str: "fooba" > strLeft ("foobar", -8) >-> Str: nil // +arg src =type Str =desc A string // +arg length =type Int =desc An integer // +arg result =type Str =desc The prefix // // //------------------ PROTO ----------------------------------------------------- strTail +Proto strTail =type fun Str Int -> Str =mode function =pkg bios =impl native =link =desc This function is similar to [[strSlice]] with nil as length. // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Str =desc A substring of src // // //------------------ PROTO ----------------------------------------------------- strLength +Proto strLength =type fun Str -> Int =mode function =pkg bios =impl native =link =desc This function returns the number of bytes in the string src. // +arg src =type Str =desc A string // +arg result =type Int =desc The number of bytes // // //------------------ PROTO ----------------------------------------------------- strLengthU16 +Proto strLengthU16 =type fun Str -> Int =mode function =pkg bios =impl native =link =desc This function returns the number of Utf-16 characters in the string src. // +arg src =type Str =desc A string // +arg result =type Int =desc The number of characters // // //------------------ PROTO ----------------------------------------------------- strLengthU8 +Proto strLengthU8 =type fun Str -> Int =mode function =pkg bios =impl native =link =desc This function returns the number of Utf-8 characters in the string src. // +arg src =type Str =desc A string // +arg result =type Int =desc The number of characters // // //------------------ PROTO ----------------------------------------------------- strListConcat +Proto strListConcat =type fun list Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string made of all the strings of the list src, in the order of the list. > strListConcat ("foo"::"bar"::nil) >-> Str: "foobar" // +arg src =type list Str =desc A list of strings // +arg result =type Str =desc A concatenation of all these strings // // //------------------ PROTO ----------------------------------------------------- strLowercase +Proto strLowercase =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string which is the lowercase conversion of src. // +arg src =type Str =desc A string // +arg result =type Str =desc The same string with only lowercase // // //------------------ PROTO ----------------------------------------------------- strPos +Proto strPos =type fun Str Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the position of a specific string in the string src. It returns nil when the pattern is not found. > strPos ("foobAr", "bA", 0) >-> Int: 3 (0x3) When the offset is negative, the search position is counted from the end of the string src. > strPos ("hello world", "l", -5) >-> Int: 9 (0x9) // +arg src =type Str =desc A string // +arg pattern =type Str =desc Another string // +arg offset =type Int =desc The position from which the search will start // +arg result =type Int =desc The first occurrence of the string pattern in the string src // // //------------------ PROTO ----------------------------------------------------- strPosRev +Proto strPosRev =type fun Str Str Int -> Int =mode function =pkg bios =impl native =link =desc This function is similar to strPos except it searches backwards. > strPosRev ("hello world", "l", nil) >-> Int: 9 (0x9) // +arg src =type Str =desc A string // +arg pattern =type Str =desc Another string // +arg offset =type Int =desc The position from which the backards search will start. A nil value means 'from the end of the string src' // +arg result =type Int =desc The last occurrence of the pattern in the string src // // //------------------ PROTO ----------------------------------------------------- strCheckPos +Proto strCheckPos =type fun Str Str Int -> Bool =mode function =pkg bios =impl native =link =desc This function returns true if the pattern is found at position offset in the string src. // +arg src =type Str =desc A string // +arg pattern =type Str =desc Another string // +arg offset =type Int =desc A position in the string src // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- strRand +Proto strRand =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string of the specified length with a random content. This function relies on the hardware generator from the host. // +arg length =type Int =desc An integer // +arg result =type Str =desc A random string // // //------------------ PROTO ----------------------------------------------------- strRead16Lsb +Proto strRead16Lsb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 16-bits LSB value which is read from the string src at position offset. > strRead16Lsb ("ABC", 1) >-> Int: 17218 (0x4342) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead16Msb +Proto strRead16Msb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 16-bits mSB value which is read from the string src at position offset. > strRead16Msb ("ABC", 1) >-> Int: 16963 (0x4243) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead24Lsb +Proto strRead24Lsb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 24-bits LSB value which is read from the string src at position offset. > strRead24Lsb ("ABCD", 1) >-> Int: 4473666 (0x444342) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead24Msb +Proto strRead24Msb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 24-bits MSB value which is read from the string src at position offset. > strRead24Msb ("ABCD", 1) >-> Int: 4342596 (0x424344) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead32Lsb +Proto strRead32Lsb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 32-bits LSB value which is read from the string src at position offset. > strRead32Lsb ("ABCDE", 1) >-> Int: 1162101570 (0x45444342) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead32Msb +Proto strRead32Msb =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned 32-bits MSB value which is read from the string src at position offset. > strRead32Msb ("ABCDE", 1) >-> Int: 1111704645 (0x42434445) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strRead8 +Proto strRead8 =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the unsigned byte value which is read from the string src at position offset. > strRead8 ("ABCDE", 1) >-> Int: 66 (0x42) It is the same function as strGet, but its name makes it similar to other strRead* functions. // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strReadU8 +Proto strReadU8 =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc // +arg A =type Str =desc // +arg B =type Int =desc // +arg result =type Int =desc // // //------------------ PROTO ----------------------------------------------------- strU8Previous +Proto strU8Previous =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc // +arg A =type Str =desc // +arg B =type Int =desc // +arg result =type Int =desc // // //------------------ PROTO ----------------------------------------------------- strU8Next +Proto strU8Next =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc // +arg A =type Str =desc // +arg B =type Int =desc // +arg result =type Int =desc // // //------------------ PROTO ----------------------------------------------------- strReadVarInt +Proto strReadVarInt =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the variable length signed value which is read from the string src at position offset. Variable length signed encoding of value V is the same as variable length unsigned encoding of V*2 where V positive or null and -V*2+1 where V is negative. Then the encoding is on 7bits MSB. The bit 7 is set to 1 except for the last byte. > strReadVarInt ("A\$c8\$68BC", 1) >-> Int: 4660 (0x1234) Starting from offset 1, the string contains two bytes 0xc8 and 0x68. - 0xc8 has bit 7 set to 1, then it is not the last byte and its 7 bits value is 0x48. - 0x68 has bit 7 set to 0, then it is the last byte and its 7 bits value is 0x68. If we concatenate these two 7bits values in Msb, we get 0x2468. It is an even number, then the encoded value is 0x2468 / 2, which is 0x1234. // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- strReadVarUInt +Proto strReadVarUInt =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the variable length unsigned value which is read from the string src at position offset. Variable length unsigned encoding of value V is on 7bits MSB. The bit 7 is set to 1 except for the last byte. > strReadVarUInt ("A\$a4\$34BC", 1) >-> Int: 4660 (0x1234) Starting from offset 1, the string contains two bytes 0xa4 and 0x34. - 0xa4 has bit 7 set to 1, then it is not the last byte and its 7 bits value is 0x24. - 0x34 has bit 7 set to 0, then it is the last byte and its 7 bits value is 0x34. If we concatenate these two 7bits values in Msb, we get 0x1234: this is the encoded value. // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc A value // // //------------------ PROTO ----------------------------------------------------- bytesReadFloat +Proto bytesReadFloat =type fun Bytes Int -> Float =mode function =pkg bios =impl native =link =desc // +arg A =type Bytes =desc // +arg B =type Int =desc // +arg result =type Float =desc // // //------------------ PROTO ----------------------------------------------------- strReadFloat +Proto strReadFloat =type fun Str Int -> Float =mode function =pkg bios =impl native =link =desc // +arg A =type Str =desc // +arg B =type Int =desc // +arg result =type Float =desc // // //------------------ PROTO ----------------------------------------------------- strReplace +Proto strReplace =type fun Str Str Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string in which ALL occurrences of search in the string src are replaced by replacement. // +arg src =type Str =desc A string // +arg search =type Str =desc The string to replace // +arg replacement =type Str =desc The replacement // +arg result =type Str =desc // // //------------------ PROTO ----------------------------------------------------- strRight +Proto strRight =type fun Str Int -> Str =mode function =pkg bios =impl native =link =desc This function returns a suffix of the string src with at most length bytes. > strRight ("foobar", 3) >-> Str: "bar" > strRight ("foobar", 8) >-> Str: "foobar" > strRight ("foobar", 0) >-> Str: nil When length is negative it is counted from the beginning of the string src > strRight ("foobar", -1) >-> Str: "oobar" > strRight ("foobar", -8) >-> Str: nil // +arg src =type Str =desc A string // +arg length =type Int =desc An integer // +arg result =type Str =desc The suffix // // //------------------ PROTO ----------------------------------------------------- strSplit +Proto strSplit =type fun Str Str -> list Str =mode function =pkg bios =impl native =link =desc This function splits a string src by the separator and returns the list of the resulting substrings. > strSplit ("-", "12-21-32-43-23") >-> list Str: > Str: "12" > Str: "21" > Str: "32" > Str: "43" > Str: "23" // +arg src =type Str =desc A string // +arg separator =type Str =desc Another string considered as the separator // +arg result =type list Str =desc A list of substrings // // //------------------ PROTO ----------------------------------------------------- strLines +Proto strLines =type fun Str -> list Str =mode function =pkg bios =impl native =link =desc This function splits a string src into lines. It handles the 3 kinds of "end of line": CR, LF, CRLF. > strLines ("hello\nworld\rfoo\r\n\bar") >-> list Str: > Str: "hello" > Str: "world" > Str: "foo" > Str: "bar" // +arg src =type Str =desc A string // +arg result =type list Str =desc A list of substrings // // //------------------ PROTO ----------------------------------------------------- strStartsWith +Proto strStartsWith =type fun Str Str -> Bool =mode function =pkg bios =impl mcy =link =desc This function returns true if the string src starts with pattern. // +arg src =type Str =desc A string // +arg pattern =type Str =desc Another string // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- strSlice +Proto strSlice =type fun Str Int Int -> Str =mode function =pkg bios =impl native =link =desc This function extracts a substring from the string src. > strSlice ("foobar", 2, 3) >-> Str: "oba" > strSlice ("foobar", 2, nil) >-> Str: "obar" > strSlice ("foobar", 2, 8) >-> Str: "obar" When the offset is negative it is counted from the end of src. > strSlice ("foobar", -2, 3) >-> Str: "ar" > strSlice ("foobar", 8, 3) >-> Str: "" > strSlice ("foobar", -8, 3) >-> Str: "" // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg len =type Int =desc Another integer // +arg result =type Str =desc A substring of src // // //------------------ PROTO ----------------------------------------------------- strSliceOfBytes +Proto strSliceOfBytes =type fun Str Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function extracts a substring from the string src and returns it as an array of bytes. When the offset is negative it is counted from the end of src. See [[strSlice]]. // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg len =type Int =desc Another integer // +arg result =type Bytes =desc An array of bytes copied from src // // //------------------ PROTO ----------------------------------------------------- strSwap +Proto strSwap =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function creates a new string which completely reverts the bytes. > strSwap ("ABCDEF") >-> Str: "FEDCBA" // +arg src =type Str =desc A string // +arg result =type Str =desc The reverted string // // //------------------ PROTO ----------------------------------------------------- floatFromStr +Proto floatFromStr =type fun Str -> Float =mode function =pkg bios =impl native =link =desc This function considers the string src as a decimal representation of a floating number. It returns this floating number. > floatFromStr ("3.1415") >-> Float: 3.1415 > floatFromStr ("1.2e5") >-> Float: 120000 > floatFromStr ("-1.2e-3") >-> Float: -0.0012 // +arg src =type Str =desc A string // +arg result =type Float =desc The float extracted from src // // //------------------ PROTO ----------------------------------------------------- sourceFromStr +Proto sourceFromStr =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function creates a new string which is how the string src could be defined in a Minimacy source code. It adds escape sequences where needed, and eventually add double quotes. > echoLn sourceFromStr ("a\nb") >"a\\nb" >-> Str: "\\\"a\\\\nb\\\"" This function is the opposite to [[strFromSource]]. // +arg src =type Str =desc A string // +arg result =type Str =desc The same string in the Minimacy syntax // // //------------------ PROTO ----------------------------------------------------- sqlFromStr +Proto sqlFromStr =type fun Str -> Str =mode function =pkg bios =impl native =link =desc The function creates a new string by adding escape sequences to src, so that it could be used in a SQL request string. It adds escape sequences where needed, and eventually add quotes at the beginning and at the end. > echoLn sqlFromStr ("a'b") >'a\\'b' >-> Str: "'a\\\\'b'" // +arg src =type Str =desc A string // +arg result =type Str =desc The same string in the SQL format // // //------------------ PROTO ----------------------------------------------------- urlFromStr +Proto urlFromStr =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function encodes the string src in a manner that can be used as values in a urls. > urlFromStr ("ab cd!") >-> Str: "ab+cd%21" It is the opposite of [[strFromUrl]]. // +arg src =type Str =desc A string // +arg result =type Str =desc The same string for use in urls. // // //------------------ PROTO ----------------------------------------------------- xmlFromStr +Proto xmlFromStr =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function encodes the string src in a manner that can be used as content in xml/html files. > xmlFromStr ("&") >-> Str: "&" // +arg src =type Str =desc A string // +arg result =type Str =desc The same string for use in xml. // // //------------------ PROTO ----------------------------------------------------- strUppercase +Proto strUppercase =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string which is the uppercase conversion of src. // +arg src =type Str =desc A string // +arg result =type Str =desc The same string with only uppercase // // //------------------ PROTO ----------------------------------------------------- strVarInt +Proto strVarInt =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the variable-length signed encoding of value. In a first step, the value V is converted as follow: V*2 when V is even, -V*2+1 when V is odd. The resulting value is expressed as 7bits MSB. And the bit 7 is set to 1 except for the last byte. See [[strReadVarInt]] for samples and for the decoding. // +arg V =type Int =desc An integer // +arg result =type Str =desc The string which encodes V as a variable-length signed integer // // //------------------ PROTO ----------------------------------------------------- strVarIntNext +Proto strVarIntNext =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function assume that a variable-length signed value is encoded at position offset in the string src. The function returns the offset of the byte just after the variable-length signed value encoding. > strVarIntNext ("A\$c8\$68BC", 1) >-> Int: 3 (0x3) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc The next offset // // //------------------ PROTO ----------------------------------------------------- strVarUInt +Proto strVarUInt =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns the variable-length unsigned encoding of value. The value V is expressed as 7bits MSB. And the bit 7 is set to 1 except for the last byte. See [[strReadVarUInt]] for samples and for the decoding. // +arg V =type Int =desc An integer // +arg result =type Str =desc The string which encodes V as a variable-length unsigned integer // // //------------------ PROTO ----------------------------------------------------- strVarUIntNext +Proto strVarUIntNext =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function assume that a variable-length unsigned value is encoded at position offset in the string src. The function returns the offset of the byte just after the variable-length signed value encoding. > strVarUIntNext ("A\$a4\$34BC", 1) >-> Int: 3 (0x3) // +arg src =type Str =desc A string // +arg offset =type Int =desc An integer // +arg result =type Int =desc The next offset // // //------------------ PROTO ----------------------------------------------------- latinFromU16Le +Proto latinFromU16Le =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF16 chars under 255. UTF16 chars above 256 are ignored. // +arg src =type Str =desc An UTF-16LE string (LSB) // +arg result =type Str =desc A Latin string // // //------------------ PROTO ----------------------------------------------------- latinFromU16Be +Proto latinFromU16Be =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF16 chars under 255. UTF16 chars above 256 are ignored. // +arg src =type Str =desc An UTF-16BE string (MSB) // +arg result =type Str =desc A Latin string // // //------------------ PROTO ----------------------------------------------------- u8FromU16Le +Proto u8FromU16Le =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF16 chars converted to UTF8. // +arg src =type Str =desc An UTF-16LE string (LSB) // +arg result =type Str =desc An UTF8 string // // //------------------ PROTO ----------------------------------------------------- u8FromU16Be +Proto u8FromU16Be =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF16 chars converted to UTF8. // +arg src =type Str =desc An UTF-16BE string (MSB) // +arg result =type Str =desc An UTF8 string // // //------------------ PROTO ----------------------------------------------------- jsonFromU8 +Proto jsonFromU8 =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function encodes the UTF8 string as a [[Json]] string. It adds escape sequences where needed, and eventually add double quotes. // +arg src =type Str =desc An UTF8 string // +arg result =type Str =desc A Json string // // //------------------ PROTO ----------------------------------------------------- latinFromU8 +Proto latinFromU8 =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF8 chars under 255. UTF8 chars above 256 are ignored. // +arg src =type Str =desc An UTF8 string // +arg result =type Str =desc A Latin string // // //------------------ PROTO ----------------------------------------------------- u16LeFromU8 +Proto u16LeFromU8 =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF8 under 65535. UTF8 chars above 65536 are ignored. // +arg src =type Str =desc An UTF8 string // +arg result =type Str =desc An UTF-16LE string (LSB) // // //------------------ PROTO ----------------------------------------------------- u16BeFromU8 +Proto u16BeFromU8 =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src UTF8 under 65535. UTF8 chars above 65536 are ignored. // +arg src =type Str =desc An UTF8 string // +arg result =type Str =desc An UTF-16BE string (MSB) // // //------------------ PROTO ----------------------------------------------------- strFromUrl +Proto strFromUrl =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function decodes the url format into a regular string. > strFromUrl ("ab+cd%21") >-> Str: "ab cd!" It is the opposite of [[urlFromStr]]. // +arg src =type Str =desc A string encoded for url // +arg result =type Str =desc The decoded string // // //------------------ PROTO ----------------------------------------------------- strFromChar +Proto strFromChar =type fun Int -> Str =mode function =pkg bios =impl native =link =desc This function returns a 1-byte string which value is byte modulo 256. > strFromChar (65) >-> Str: "A" // +arg byte =type Int =desc An integer which is more likely between 0 and 255 // +arg result =type Str =desc A 1-byte string // // //------------------ PROTO ----------------------------------------------------- hexFilter +Proto hexFilter =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a new string which is obtained from src by removing any character which is not an hexadecimal digit. > hexFilter ("01 02\n\t03 04") >-> Str: "01020304" // +arg src =type Str =desc A string // +arg result =type Str =desc The filtered string // // //------------------ PROTO ----------------------------------------------------- strFromHex +Proto strFromHex =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function converts an hexadecimal string into its binary content. > strFromHex ("4c616D626461") >-> Str: "Lambda" // +arg src =type Str =desc A string containing hexadecimal digits // +arg result =type Str =desc The decoded binary string // // //------------------ PROTO ----------------------------------------------------- intFromHex +Proto intFromHex =type fun Str -> Int =mode function =pkg bios =impl native =link =desc This function assumes that the string src is the hexadecimal representation of an integer, and returns this integer. > intFromHex ("1000000") >-> Int: 16777216 (0x1000000) Be aware that this function can lead to overflow when the encoded integer is to big. Remember that Minimacy integers are 64-bits signed. > intFromHex ("2000000000000000") >-> Int: -2305843009213693952 (0xE000000000000000) > intFromHex ("4000000000000000") >-> Int: 0 (0x0) // +arg src =type Str =desc A string containing hexadecimal digits // +arg result =type Int =desc The encoded integer // // //------------------ PROTO ----------------------------------------------------- isHex +Proto isHex =type fun Str -> Bool =mode function =pkg bios =impl native =link =desc This function returns true if the string src may be considered as hex encoding. // +arg src =type Str =desc A string // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- isU8 +Proto isU8 =type fun Str -> Bool =mode function =pkg bios =impl native =link =desc This function returns true if the string src may be considered as UTF8 encoding. Not any string can pretend to be UTF8, for example "\\$81". > isU8 ("\$c2\$82") >-> Bool: true > isU8 ("\$81") >-> Bool: false // +arg src =type Str =desc A string // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- u8FromJson +Proto u8FromJson =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function assumes that the string src is a [[Json]] string, inside double quotes and with [[Json]] string escape sequences. It decodes it an returns the resulting UTF8 string. > u8FromJson ("\\"foob\u0061r\\"") >-> Str: "foobar" // +arg src =type Str =desc A Json string // +arg result =type Str =desc An UTF8 string // // //------------------ PROTO ----------------------------------------------------- u16LeFromLatin +Proto u16LeFromLatin =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src Latin chars converted to UTF16. // +arg A =type Str =desc A Latin string // +arg result =type Str =desc An UTF-16LE string (LSB) // // //------------------ PROTO ----------------------------------------------------- u16BeFromLatin +Proto u16BeFromLatin =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src Latin chars converted to UTF16. // +arg A =type Str =desc A Latin string // +arg result =type Str =desc An UTF-16BE string (MSB) // // //------------------ PROTO ----------------------------------------------------- u8FromLatin +Proto u8FromLatin =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function returns a string with all src Latin chars converted to UTF8. // +arg A =type Str =desc A Latin string // +arg result =type Str =desc An UTF8 string // // //------------------ PROTO ----------------------------------------------------- strFromSource +Proto strFromSource =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function is the opposite to [[sourceFromStr]]. > strFromSource ("\"a\\nb\"") >-> Str: "a\\nb" // +arg src =type Str =desc A string representing a string declaration in the Minimacy syntax // +arg result =type Str =desc The decoded string // // //------------------ PROTO ----------------------------------------------------- strTrim +Proto strTrim =type fun Str -> Str =mode function =pkg bios =impl mcy =link =desc This function removes all bytes equal or lower than 32 at the beginning and at the end of src. > strTrim ("\tfoobar \n") >-> Str: "foobar" // +arg src =type Str =desc A string // +arg result =type Str =desc The filtered string // // //------------------ PROTO ----------------------------------------------------- latinFromXml +Proto latinFromXml =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function decodes the xml/html string src. It decodes the html entities such as & // +arg src =type Str =desc An xml/html string // +arg result =type Str =desc A Latin string // // //------------------ PROTO ----------------------------------------------------- u8FromXml +Proto u8FromXml =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function decodes the xml/html string src. It decodes the html entities such as & // +arg src =type Str =desc An xml/html string // +arg result =type Str =desc An UTF8 string // // //------------------ PROTO ----------------------------------------------------- hexFromStr +Proto hexFromStr =type fun Str -> Str =mode function =pkg bios =impl native =link =desc The hexadecimal representation of the content of the string. Each byte of the string src is converted into 2 hexadecimal digits, lowercase. > hexFromStr ("foobar") >-> Str: "666f6f626172" It is the opposite to function strFromHex. // +arg src =type Str =desc Any string // +arg result =type Str =desc A string containing only hexadecimal digits // // //------------------ PROTO ----------------------------------------------------- strWithLF +Proto strWithLF =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function is used to homogenize the ends of line of the string src. Three systems coexist in the computing world: LF, CR and CR LF. LF stands for 'line feed' and has ascii code 10, CR stands for 'carriage return' and has ascii code 13. Usual escape sequences are \\n for LF, \\r for CR. You're probably already familiar with them. It makes your computation easier when you first homogenize the ends of line of your data. This function converts all the ends of line of src into LF. > strWithLF ("a\nb\r\nc\rd") >-> Str: "a\\nb\\nc\\nd" // +arg src =type Str =desc Any string // +arg result =type Str =desc A string with only LF ends of line. // // //------------------ PROTO ----------------------------------------------------- strWithCR +Proto strWithCR =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function is used to homogenize the ends of line of the string src. Three systems coexist in the computing world: LF, CR and CR LF. LF stands for 'line feed' and has ascii code 10, CR stands for 'carriage return' and has ascii code 13. Usual escape sequences are \\n for LF, \\r for CR. You're probably already familiar with them. It makes your computation easier when you first homogenize the ends of line of your data. This function converts all the ends of line of src into CR. > strWithCR ("a\nb\r\nc\rd") >-> Str: "a\\rb\\rc\\rd" // +arg src =type Str =desc Any string // +arg result =type Str =desc A string with only CR ends of line. // // //------------------ PROTO ----------------------------------------------------- strWithCRLF +Proto strWithCRLF =type fun Str -> Str =mode function =pkg bios =impl native =link =desc This function is used to homogenize the ends of line of the string src. Three systems coexist in the computing world: LF, CR and CR LF. LF stands for 'line feed' and has ascii code 10, CR stands for 'carriage return' and has ascii code 13. Usual escape sequences are \\n for LF, \\r for CR. You're probably already familiar with them. It makes your computation easier when you first homogenize the ends of line of your data. This function converts all the ends of line of src into CR LF. > strWithCRLF ("a\nb\r\nc\rd") >-> Str: "a\\r\\nb\\r\\nc\\r\\nd" // +arg src =type Str =desc Any string // +arg result =type Str =desc A string with only CR LF ends of line. // // //------------------ PROTO ----------------------------------------------------- strPadWithSpace +Proto strPadWithSpace =type fun Int Str -> Str =mode function =pkg bios =impl mcy =link =desc This function returns un new string in which a padding is added at the beginning so that the resulting string length is N. When the length of src exceeds N, it returns the N-1 first bytes of src followed by a star. // +arg N =type Int =desc A positive integer // +arg src =type Str =desc A string // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- strEmpty +Proto strEmpty =type fun Str -> Bool =mode function =pkg bios =impl mcy =link =desc This function returns true if the string str is nil or "". // +arg src =type Str =desc A string // +arg result =type Bool =desc A boolean // // //------------------ PROTO ----------------------------------------------------- strFormat +Proto strFormat =type fun Str * -> Str =mode function =pkg bios =impl mcy =link =desc This function returns a new string computed from the format string and any number of arguments. The format is a regular string in which each star '*' character will be replaced by one of the following arguments. > strFormat ("Hello *!", "foobar") >-> Str: "Hello foobar!" > strFormat "pi is * and e is *" pi e >-> Str: "pi is 3.14159 and e is 2.71828" To understand how arguments of any type are displayed, see [[strBuild]]. // +arg format =type Str =desc A string // +arg data =type * =desc Any number of expressions of any type // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- strCreate +Proto strCreate =type fun Int Int -> Str =mode function =pkg bios =impl native =link =desc This function creates a string, by specifying its length and the value for all its bytes. // +arg length =type Int =desc A positive integer // +arg value =type Int =desc A byte value // +arg result =type Str =desc A new string // // //------------------ PROTO ----------------------------------------------------- strFromBytes +Proto strFromBytes =type fun Bytes -> Str =mode function =pkg bios =impl native =link =desc This function creates a new string with the same content as the array of bytes. // +arg src =type Bytes =desc Any array of bytes // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- strLowercaseU16Be +Proto strLowercaseU16Be =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the lowercase conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Big-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strLowercaseU16Le +Proto strLowercaseU16Le =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the lowercase conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Little-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strLowercaseU8 +Proto strLowercaseU8 =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the lowercase conversion of string. // +arg string =type Str =desc The input string encoded in UTF-8 // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strSearchcase +Proto strSearchcase =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is a lowercase unaccented conversion of string, suitable for search features. // +arg string =type Str =desc The input string encoded in Latin // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strSearchcaseU16Be +Proto strSearchcaseU16Be =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is a lowercase unaccented conversion of string, suitable for search features. // +arg string =type Str =desc The input string encoded in Unicode Big-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strSearchcaseU16Le +Proto strSearchcaseU16Le =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is a lowercase unaccented conversion of string, suitable for search features. // +arg string =type Str =desc The input string encoded in Unicode Little-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strSearchcaseU8 +Proto strSearchcaseU8 =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is a lowercase unaccented conversion of string, suitable for search features. // +arg string =type Str =desc The input string encoded in UTF-8 // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUnaccented +Proto strUnaccented =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is an unaccented conversion of string. // +arg string =type Str =desc The input string encoded in Latin // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUnaccentedU16Be +Proto strUnaccentedU16Be =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is an unaccented conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Big-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUnaccentedU16Le +Proto strUnaccentedU16Le =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is an unaccented conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Little-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUnaccentedU8 +Proto strUnaccentedU8 =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is an unaccented conversion of string. // +arg string =type Str =desc The input string encoded in UTF-8 // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUppercaseU16Be +Proto strUppercaseU16Be =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the uppercase conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Big-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUppercaseU16Le +Proto strUppercaseU16Le =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the uppercase conversion of string. // +arg string =type Str =desc The input string encoded in Unicode Little-Endian // +arg result =type Str =desc The resulting string // // //------------------ PROTO ----------------------------------------------------- strUppercaseU8 +Proto strUppercaseU8 =type fun Str -> Str =mode Function =pkg bios =impl native =link =desc This function returns a new string which is the uppercase conversion of string. // +arg string =type Str =desc The input string encoded in UTF-8 // +arg result =type Str =desc The resulting string