forked from solstice/solstice
started writing lexer after making string lib
This commit is contained in:
24
string/docs/char_at.md
Normal file
24
string/docs/char_at.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_CharAt
|
||||
Get character at index in string.
|
||||
|
||||
## Arguments
|
||||
- str (string): string to get character of.
|
||||
- index (int): the index in the string you want to get.
|
||||
|
||||
## Returns
|
||||
char (string): the character at the specified index in the string.
|
||||
|
||||
## Raises
|
||||
- `OutOfBounds`: raised if you try accessing a string past its length or at a negative index.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_CharAt "my string" 3 &char
|
||||
println $char # "s"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_CharAt("my string", 3) // "s"
|
||||
```
|
||||
25
string/docs/check/contains.md
Normal file
25
string/docs/check/contains.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# string_Contains
|
||||
Check if a string has another string in it.
|
||||
|
||||
## Arguments
|
||||
- haystack (string): the string to check against.
|
||||
- needle (string): the string to look for.
|
||||
|
||||
## Returns
|
||||
found (bool): returns `true` if `haystack` has `needle` inside it.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Contains "The task was completed successfully." "success" &found
|
||||
println $found # true
|
||||
|
||||
call !string_Contains "The task failed." "success" &found
|
||||
println $found # false
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Contains("The task was completed successfully.", "success") // true
|
||||
puts string_Contains("The task failed.", "success") // false
|
||||
```
|
||||
25
string/docs/check/ends_with.md
Normal file
25
string/docs/check/ends_with.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# string_EndsWith
|
||||
Check if a string has another string as a suffix.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check against.
|
||||
- suffix (string): the suffix to check for.
|
||||
|
||||
## Returns
|
||||
hasSuffix (bool): returns `true` if `str` has the given `suffix` as a suffix, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_EndsWith "file.txt" ".txt" &hasSuffix
|
||||
println $hasSuffix # true
|
||||
|
||||
call !string_EndsWith "file.grnd" ".txt" &hasSuffix
|
||||
println $hasSuffix # false
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_EndsWith("file.txt", ".txt") // true
|
||||
puts string_EndsWith("file.grnd", ".txt") // false
|
||||
```
|
||||
25
string/docs/check/starts_with.md
Normal file
25
string/docs/check/starts_with.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# string_StartsWith
|
||||
Check if a string is prefixed by another string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check against.
|
||||
- prefix (string): the prefix to check for.
|
||||
|
||||
## Returns
|
||||
hasPrefix (bool): returns `true` if `str` is prefixed by the given `prefix`, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_StartsWith "doc_someFile.txt" "doc_" &hasPrefix
|
||||
println $hasPrefix # true
|
||||
|
||||
call !string_StartsWith "someFile.txt" "doc_" &hasPrefix
|
||||
println $hasPrefix # false
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_StartsWith("doc_someFile.txt", "doc_") // true
|
||||
puts string_StartsWith("someFile.txt", "doc_") // false
|
||||
```
|
||||
24
string/docs/classify/is_alnum.md
Normal file
24
string/docs/classify/is_alnum.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_IsAlnum
|
||||
Returns true if the given `string` is alphanumeric.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check.
|
||||
|
||||
## Returns
|
||||
isAlnum (bool): returns `true` if `string` is alphanumeric, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_IsAlnum "abc123" &isAlnum
|
||||
println $isAlnum # true
|
||||
|
||||
call !string_IsAlnum "@$!ffasdf" &isAlnum
|
||||
println $isAlnum # false
|
||||
|
||||
call !string_IsAlnum "1234" &isAlnum
|
||||
println $isAlnum # true
|
||||
|
||||
call !string_IsAlnum "_" &isAlnum
|
||||
println $isAlnum # false
|
||||
```
|
||||
24
string/docs/classify/is_alpha.md
Normal file
24
string/docs/classify/is_alpha.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_IsAlpha
|
||||
Returns true if the given `string` is only the letters a-Z.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check.
|
||||
|
||||
## Returns
|
||||
isAlpha (bool): returns `true` if `string` is only the letters a-Z, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_IsAlpha "abcABC" &isAlpha
|
||||
println $isAlpha # true
|
||||
|
||||
call !string_IsAlpha "123" &isAlpha
|
||||
println $isAlpha # false
|
||||
|
||||
call !string_IsAlpha "abc_$@" &isAlpha
|
||||
println $isAlpha # false
|
||||
|
||||
call !string_IsAlpha "aAbBcCdDeEfF" &isAlpha
|
||||
println $isAlpha # true
|
||||
```
|
||||
24
string/docs/classify/is_digit copy.md
Normal file
24
string/docs/classify/is_digit copy.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_IsAlpha
|
||||
Returns true if the given `string` is only numbers.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check.
|
||||
|
||||
## Returns
|
||||
isAlpha (bool): returns `true` if `string` is only numbers, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_IsAlpha "65535" &isAlpha
|
||||
println $isAlpha # true
|
||||
|
||||
call !string_IsAlpha "$!@/_ffff" &isAlpha
|
||||
println $isAlpha # false
|
||||
|
||||
call !string_IsAlpha "1234" &isAlpha
|
||||
println $isAlpha # true
|
||||
|
||||
call !string_IsAlpha "abcd123" &isAlpha
|
||||
println $isAlpha # false
|
||||
```
|
||||
24
string/docs/classify/is_space.md
Normal file
24
string/docs/classify/is_space.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_IsSpace
|
||||
Returns true if the given `string` is whitespace.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to check.
|
||||
|
||||
## Returns
|
||||
isAlpha (bool): returns `true` if `string` is whitespace, otherwise `false`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_IsAlpha " " &isAlpha
|
||||
println $isAlpha # true
|
||||
|
||||
call !string_IsAlpha " " &isAlpha
|
||||
println $isAlpha # true
|
||||
|
||||
call !string_IsAlpha "abc_def" &isAlpha
|
||||
println $isAlpha # false
|
||||
|
||||
call !string_IsAlpha " a" &isAlpha
|
||||
println $isAlpha # false
|
||||
```
|
||||
21
string/docs/find/count.md
Normal file
21
string/docs/find/count.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# string_Count
|
||||
Count the number of times `needle` appears in `haystack`.
|
||||
|
||||
## Arguments
|
||||
- haystack (string): the string to search through.
|
||||
- needle (string): the substring to count.
|
||||
|
||||
## Returns
|
||||
count (int): the number of times `needle` appears in `haystack`.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Count "Hello, World!" "l" &count
|
||||
println $count # 3
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Count("Hello, World!", "l") // 3
|
||||
```
|
||||
21
string/docs/find/find.md
Normal file
21
string/docs/find/find.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# string_Find
|
||||
Look for the first occurence of `needle` in `haystack` and return its index in the string. If it isn't found, return -1.
|
||||
|
||||
## Arguments
|
||||
- haystack (string): the string to search.
|
||||
- needle (string): the substring to look for.
|
||||
|
||||
## Returns
|
||||
index (int): the index of the first occurence of `needle` in `haystack`. If it isn't found, return -1.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Find "abcdefg" "d" &index
|
||||
println $index # 3
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Find("abcdefg", "d") // 3
|
||||
```
|
||||
21
string/docs/find/find_last.md
Normal file
21
string/docs/find/find_last.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# string_FindLast
|
||||
Look for the last occurence of `needle` in `haystack` and return its index in the string. If it isn't found, return -1.
|
||||
|
||||
## Arguments
|
||||
- haystack (string): the string to search.
|
||||
- needle (string): the substring to look for.
|
||||
|
||||
## Returns
|
||||
index (int): the index of the last occurence of `needle` in `haystack`. If it isn't found, return -1.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_FindLast "abcabcabc" "b" &index
|
||||
println $index # 7
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_FindLast("abcabcabc", "b") // 7
|
||||
```
|
||||
23
string/docs/modify/lower.md
Normal file
23
string/docs/modify/lower.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_Lower
|
||||
Make a string lowercase.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to make lowercase.
|
||||
|
||||
## Returns
|
||||
lowerString (string): the string in lowercase.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Lower "my STRING" &lowerString
|
||||
println $lowerString # "my string"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Lower("my STRING") // "my string"
|
||||
```
|
||||
24
string/docs/modify/repeat.md
Normal file
24
string/docs/modify/repeat.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# string_Repeat
|
||||
Repeat a string `times` times.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to repeat.
|
||||
- times (int): the number of times to repeat the string.
|
||||
|
||||
## Returns
|
||||
result (string): the string repeated the given number of times.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground fails to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Repeat "hi " 5 &repeated
|
||||
println $repeated # "hi hi hi hi hi "
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Repeat("hi ", 5) // "hi hi hi hi hi "
|
||||
```
|
||||
22
string/docs/modify/replace.md
Normal file
22
string/docs/modify/replace.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# string_Replace
|
||||
Replace all occurences of `from` in `str` with `to`.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to run a find and replace on.
|
||||
- from (string): the substring you want to replace.
|
||||
- to (string): the thing to replace all occurences of `from` with.
|
||||
|
||||
## Returns
|
||||
result (string): the resulting string after the find and replace.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Replace "abacabacacacabacacacabac" "c" "b" &result
|
||||
println $result # "abababababababababababab"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Replace("abacabacacacabacacacabac", "c", "b") // "abababababababababababab"
|
||||
```
|
||||
23
string/docs/modify/reverse.md
Normal file
23
string/docs/modify/reverse.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_Reverse
|
||||
Get the reversed version of a string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to reverse.
|
||||
|
||||
## Returns
|
||||
result (string): the reversed string.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Reverse "Hello, World!" &reverse
|
||||
println $reverse # "!dlroW, olleH"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Reverse("Hello, World!") // "!dlroW, olleH"
|
||||
```
|
||||
27
string/docs/modify/substring.md
Normal file
27
string/docs/modify/substring.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# string_Substring
|
||||
Get a substring of a string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to get a substring of.
|
||||
- start (int): starting index of the substring.
|
||||
- end (int): ending index of the substring.
|
||||
|
||||
## Returns
|
||||
substring (string): the substring of the given string.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
- `EndBeforeStart`: raised if the `end` index is less than the `start` index.
|
||||
- `OutOfBounds`: raised if either the `end` or `start` index is outside the bounds of the string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Substring "Hello, World!" 1 3 &sub
|
||||
println $sub # "ell"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Substring("Hello, World!", 1, 3) // "ell"
|
||||
```
|
||||
23
string/docs/modify/trim.md
Normal file
23
string/docs/modify/trim.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_Trim
|
||||
Trim whitespace from both sides of a string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to trim.
|
||||
|
||||
## Returns
|
||||
trimmed (string): the string with its whitespace removed.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Trim " aaabbb " &trimmed
|
||||
println $trimmed # "aaabbb"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Trim(" aaabbb ") // "aaabbb"
|
||||
```
|
||||
23
string/docs/modify/trim_left.md
Normal file
23
string/docs/modify/trim_left.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_TrimLeft
|
||||
Trim whitespace from the left side of a string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to trim.
|
||||
|
||||
## Returns
|
||||
trimmed (string): the string with the whitespace removed on the left side.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_TrimLeft " aaabbb " &trimmed
|
||||
println $trimmed # "aaabbb "
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_TrimLeft(" aaabbb ") // "aaabbb "
|
||||
```
|
||||
23
string/docs/modify/trim_right.md
Normal file
23
string/docs/modify/trim_right.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_TrimRight
|
||||
Trim whitespace from the right side of a string.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to trim.
|
||||
|
||||
## Returns
|
||||
trimmed (string): the string with the whitespace removed on the right side.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_TrimRight " aaabbb " &trimmed
|
||||
println $trimmed # " aaabbb"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_TrimRight(" aaabbb ") // " aaabbb"
|
||||
```
|
||||
23
string/docs/modify/upper.md
Normal file
23
string/docs/modify/upper.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# string_Upper
|
||||
Make a string uppercase.
|
||||
|
||||
## Arguments
|
||||
- str (string): the string to make uppercase.
|
||||
|
||||
## Returns
|
||||
upperString (string): the string in uppercase.
|
||||
|
||||
## Raises
|
||||
- `AllocFail`: raised if Ground failed to allocate memory for the new string.
|
||||
|
||||
## Example
|
||||
### Ground
|
||||
```python
|
||||
call !string_Upper "MY string" &upperString
|
||||
println $upperString # "MY STRING"
|
||||
```
|
||||
|
||||
### Solstice
|
||||
```c
|
||||
puts string_Upper("MY string") // "MY STRING"
|
||||
```
|
||||
Reference in New Issue
Block a user