Add reverse case function
This commit is contained in:
28
README.md
28
README.md
@@ -386,6 +386,32 @@ $ upper "HELLO"
|
|||||||
HELLO
|
HELLO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Reverse a string case
|
||||||
|
|
||||||
|
**CAVEAT:** Requires `bash` 4+
|
||||||
|
|
||||||
|
**Example Function:**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
reverse_case() {
|
||||||
|
# Usage: reverse_case "string"
|
||||||
|
printf '%s\n' "${1~~}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example Usage:**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ reverse_case "hello"
|
||||||
|
HELLO
|
||||||
|
|
||||||
|
$ reverse_case "HeLlO"
|
||||||
|
hElLo
|
||||||
|
|
||||||
|
$ reverse_case "HELLO"
|
||||||
|
hello
|
||||||
|
```
|
||||||
|
|
||||||
## Trim quotes from a string
|
## Trim quotes from a string
|
||||||
|
|
||||||
**Example Function:**
|
**Example Function:**
|
||||||
@@ -1221,6 +1247,8 @@ Contrary to popular belief, there is no issue in utilizing raw escape sequences.
|
|||||||
| `${VAR^^}` | Uppercase all characters. | `bash 4+` |
|
| `${VAR^^}` | Uppercase all characters. | `bash 4+` |
|
||||||
| `${VAR,}` | Lowercase first character. | `bash 4+` |
|
| `${VAR,}` | Lowercase first character. | `bash 4+` |
|
||||||
| `${VAR,,}` | Lowercase all characters. | `bash 4+` |
|
| `${VAR,,}` | Lowercase all characters. | `bash 4+` |
|
||||||
|
| `${VAR~}` | Reverse case of first character. | `bash 4+` |
|
||||||
|
| `${VAR~~}` | Reverse case of all characters. | `bash 4+` |
|
||||||
|
|
||||||
|
|
||||||
## Default Value
|
## Default Value
|
||||||
|
|||||||
@@ -209,6 +209,32 @@ $ upper "HELLO"
|
|||||||
HELLO
|
HELLO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Reverse a string case
|
||||||
|
|
||||||
|
**CAVEAT:** Requires `bash` 4+
|
||||||
|
|
||||||
|
**Example Function:**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
reverse_case() {
|
||||||
|
# Usage: reverse_case "string"
|
||||||
|
printf '%s\n' "${1~~}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example Usage:**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ reverse_case "hello"
|
||||||
|
HELLO
|
||||||
|
|
||||||
|
$ reverse_case "HeLlO"
|
||||||
|
hElLo
|
||||||
|
|
||||||
|
$ reverse_case "HELLO"
|
||||||
|
hello
|
||||||
|
```
|
||||||
|
|
||||||
## Trim quotes from a string
|
## Trim quotes from a string
|
||||||
|
|
||||||
**Example Function:**
|
**Example Function:**
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
| `${VAR^^}` | Uppercase all characters. | `bash 4+` |
|
| `${VAR^^}` | Uppercase all characters. | `bash 4+` |
|
||||||
| `${VAR,}` | Lowercase first character. | `bash 4+` |
|
| `${VAR,}` | Lowercase first character. | `bash 4+` |
|
||||||
| `${VAR,,}` | Lowercase all characters. | `bash 4+` |
|
| `${VAR,,}` | Lowercase all characters. | `bash 4+` |
|
||||||
|
| `${VAR~}` | Reverse case of first character. | `bash 4+` |
|
||||||
|
| `${VAR~~}` | Reverse case of all characters. | `bash 4+` |
|
||||||
|
|
||||||
|
|
||||||
## Default Value
|
## Default Value
|
||||||
|
|||||||
5
test.sh
5
test.sh
@@ -28,6 +28,11 @@ test_upper() {
|
|||||||
assert_equals "$result" "HELLO"
|
assert_equals "$result" "HELLO"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_reverse_case() {
|
||||||
|
result="$(reverse_case "HeLlO")"
|
||||||
|
assert_equals "$result" "hElLo"
|
||||||
|
}
|
||||||
|
|
||||||
test_trim_quotes() {
|
test_trim_quotes() {
|
||||||
result="$(trim_quotes "\"te'st' 'str'ing\"")"
|
result="$(trim_quotes "\"te'st' 'str'ing\"")"
|
||||||
assert_equals "$result" "test string"
|
assert_equals "$result" "test string"
|
||||||
|
|||||||
Reference in New Issue
Block a user