String case: Difference between revisions
Content added Content deleted
(→{{header|GDScript}}: Fix up some mistakes) |
(→{{header|jq}}: case-insensitive search) |
||
Line 1,938: | Line 1,938: | ||
=={{header|jq}}== |
=={{header|jq}}== |
||
'''Works with jq and gojq, the C and Go implementations of jq''' |
|||
If your version of jq does not have ascii_downcase and ascii_upcase, then you might want to use their definitions: |
If your version of jq does not have ascii_downcase and ascii_upcase, then you might want to use their definitions: |
||
<syntaxhighlight lang="jq"># like ruby's downcase - only characters A to Z are affected |
<syntaxhighlight lang="jq"># like ruby's downcase - only characters A to Z are affected |
||
Line 1,945: | Line 1,947: | ||
# like ruby's upcase - only characters a to z are affected |
# like ruby's upcase - only characters a to z are affected |
||
def ascii_upcase: |
def ascii_upcase: |
||
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode; |
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode; |
||
</syntaxhighlight> |
|||
jq's regular expression functions have a "case insensitive" option that is often useful |
|||
when handling text outside the ASCII range, as is illustrated by the last example below. |
|||
Currently, however, there is no built-in case-conversion filter for Unicode characters in general. |
|||
'''Examples''': |
'''Examples''': |
||
<syntaxhighlight lang="jq"> |
<syntaxhighlight lang="jq"> |
||
"alphaBETA" | ascii_upcase |
|||
#=> "ALPHABETA" |
#=> "ALPHABETA" |
||
"alphaBETA" | ascii_downcase |
"alphaBETA" | ascii_downcase |
||
#=> "alphabeta" |
#=> "alphabeta" |
||
jq -n '"á" | test("Á";"i")' # case-insensitive search |
|||
#=> true |
|||
</syntaxhighlight> |
|||
=={{header|Jsish}}== |
=={{header|Jsish}}== |