-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
174 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,176 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Unicode Case Conversions\n", | ||
"\n", | ||
"Uppercasing or lowercasing a character may result in more than one character. Also, depending on the position of a character in a word, you can get a different uppercase or lowercase character." | ||
] | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/sualeh/What-a-Character/blob/go/Notebooks/2_go_unicode_case_conversions.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "Bozr-lpRPIE-" | ||
}, | ||
"source": [ | ||
"# Unicode Case Conversions\n", | ||
"\n", | ||
"Uppercasing or lowercasing a character may result in more than one character. Also, depending on the position of a character in a word, you can get a different uppercase or lowercase character." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "NHueUYPbPIE_" | ||
}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"## Google Colab\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to `Go (gonb)`. Refresh the browser before running any subsequent code. If you are not running the notebook in Google Colab, skip this section." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "7SM4ltoBPIE_" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Prepare Google Colab for Go Kernel\n", | ||
"\n", | ||
"# Install Go and goimports.\n", | ||
"!echo -n \"Installing go ...\"\n", | ||
"!mkdir -p cache\n", | ||
"!wget -q -O cache/go.tar.gz 'https://go.dev/dl/go1.22.2.linux-amd64.tar.gz'\n", | ||
"!tar xzf cache/go.tar.gz\n", | ||
"%env GOROOT=/content/go\n", | ||
"!ln -sf \"/content/go/bin/go\" /usr/bin/go\n", | ||
"!echo \" done.\"\n", | ||
"!go version\n", | ||
"\n", | ||
"# Install gonb, goimports, gopls.\n", | ||
"!echo -n \"Installing gonb ...\"\n", | ||
"!go install github.com/janpfeifer/gonb@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gonb /usr/bin/gonb\n", | ||
"\n", | ||
"!echo -n \"Installing goimports ...\"\n", | ||
"!go install golang.org/x/tools/cmd/goimports@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/goimports /usr/bin/goimports\n", | ||
"\n", | ||
"!echo -n \"Installing gopls ...\"\n", | ||
"!go install golang.org/x/tools/gopls@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gopls /usr/bin/gopls\n", | ||
"\n", | ||
"# Install gonb kernel configuration.\n", | ||
"!gonb --install --logtostderr\n", | ||
"!echo \"Done!\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "p8pypgI6PIFA" | ||
}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "c7b1GE7mPIFA" | ||
}, | ||
"source": [ | ||
"## Lower Case\n", | ||
"\n", | ||
"In Greek, the word for dog in lowercase is \"σκύλος\". Notice that the first and last letter are both sigma." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "hAbU_I7KPIFA" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%\n", | ||
"greekWord := \"ΣΚΎΛΟΣ\" // dog\n", | ||
"greekUpper := strings.ToUpper(greekWord)\n", | ||
"greekLower := strings.ToLower(greekUpper)\n", | ||
"\n", | ||
"fmt.Printf(\"Greek \\\"dog\\\" - \\\"%s\\\" - length %d\\n\", greekWord, utf8.RuneCountInString(greekWord))\n", | ||
"fmt.Printf(\"Converted to uppercase - \\\"%s\\\"\\n\", greekUpper)\n", | ||
"fmt.Printf(\"Converted to lowercase - \\\"%s\\\"\\n\", greekLower)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "lckqhT1ZPIFA" | ||
}, | ||
"source": [ | ||
"## Upper Case\n", | ||
"\n", | ||
"[**U+1E9E LATIN CAPITAL LETTER SHARP S**](http://unicode.org/versions/Unicode5.1.0/#Tailored_Casing_Operations)\n", | ||
"\n", | ||
"In particular, capital sharp s is intended for typographical representations of signage and uppercase titles, and other environments where users require the sharp s to be preserved in uppercase. Overall, such usage is rare. In contrast, standard German orthography uses the string \"SS\" as uppercase mapping for small sharp s. Thus, with the default Unicode casing operations, capital sharp s will lowercase to small sharp s, but not the reverse: small sharp s uppercases to \"SS\". In those instances where the reverse casing operation is needed, a tailored operation would be required.\n", | ||
"\n", | ||
"When the German word \"straße\" is converted to uppercase \"STRASSE\", Notice that the string lengths are different." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "siJj_L00PIFB" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%\n", | ||
"germanWord := \"straße\" // street\n", | ||
"germanUpper := strings.ToUpper(germanWord)\n", | ||
"germanLower := strings.ToLower(germanUpper)\n", | ||
"\n", | ||
"fmt.Printf(\"German \\\"street\\\" - \\\"%s\\\" - length %d\\n\", germanWord, utf8.RuneCountInString(germanWord))\n", | ||
"fmt.Printf(\"Converted to uppercase - \\\"%s\\\" - length %d\\n\", germanUpper, utf8.RuneCountInString(germanUpper))\n", | ||
"fmt.Printf(\"Converted to lowercase - \\\"%s\\\" - length %d\\n\", germanLower, utf8.RuneCountInString(germanLower))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
}, | ||
"colab": { | ||
"provenance": [], | ||
"include_colab_link": true | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"## Google Colab\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to `Go (gonb)`. Refresh the browser before running any subsequent code. If you are not running the notebook in Google Colab, skip this section." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Prepare Google Colab for Go Kernel\n", | ||
"\n", | ||
"# Install Go and goimports.\n", | ||
"!echo -n \"Installing go ...\"\n", | ||
"!mkdir -p cache\n", | ||
"!wget -q -O cache/go.tar.gz 'https://go.dev/dl/go1.22.2.linux-amd64.tar.gz'\n", | ||
"!tar xzf cache/go.tar.gz\n", | ||
"%env GOROOT=/content/go\n", | ||
"!ln -sf \"/content/go/bin/go\" /usr/bin/go\n", | ||
"!echo \" done.\"\n", | ||
"!go version\n", | ||
"\n", | ||
"# Install gonb, goimports, gopls.\n", | ||
"!echo -n \"Installing gonb ...\"\n", | ||
"!go install github.com/janpfeifer/gonb@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gonb /usr/bin/gonb\n", | ||
"\n", | ||
"!echo -n \"Installing goimports ...\"\n", | ||
"!go install golang.org/x/tools/cmd/goimports@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/goimports /usr/bin/goimports\n", | ||
"\n", | ||
"!echo -n \"Installing gopls ...\"\n", | ||
"!go install golang.org/x/tools/gopls@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gopls /usr/bin/gopls\n", | ||
"\n", | ||
"# Install gonb kernel configuration.\n", | ||
"!gonb --install --logtostderr\n", | ||
"!echo \"Done!\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Lower Case\n", | ||
"\n", | ||
"In Greek, the word for dog in lowercase is \"σκύλος\". Notice that the first and last letter are both sigma." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%\n", | ||
"greekWord := \"ΣΚΎΛΟΣ\" // dog\n", | ||
"greekUpper := strings.ToUpper(greekWord)\n", | ||
"greekLower := strings.ToLower(greekUpper)\n", | ||
"\n", | ||
"fmt.Printf(\"Greek \\\"dog\\\" - \\\"%s\\\" - length %d\\n\", greekWord, utf8.RuneCountInString(greekWord))\n", | ||
"fmt.Printf(\"Converted to uppercase - \\\"%s\\\"\\n\", greekUpper)\n", | ||
"fmt.Printf(\"Converted to lowercase - \\\"%s\\\"\\n\", greekLower)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Upper Case\n", | ||
"\n", | ||
"[**U+1E9E LATIN CAPITAL LETTER SHARP S**](http://unicode.org/versions/Unicode5.1.0/#Tailored_Casing_Operations)\n", | ||
"\n", | ||
"In particular, capital sharp s is intended for typographical representations of signage and uppercase titles, and other environments where users require the sharp s to be preserved in uppercase. Overall, such usage is rare. In contrast, standard German orthography uses the string \"SS\" as uppercase mapping for small sharp s. Thus, with the default Unicode casing operations, capital sharp s will lowercase to small sharp s, but not the reverse: small sharp s uppercases to \"SS\". In those instances where the reverse casing operation is needed, a tailored operation would be required.\n", | ||
"\n", | ||
"When the German word \"straße\" is converted to uppercase \"STRASSE\", Notice that the string lengths are different." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%\n", | ||
"germanWord := \"straße\" // street\n", | ||
"germanUpper := strings.ToUpper(germanWord)\n", | ||
"germanLower := strings.ToLower(germanUpper)\n", | ||
"\n", | ||
"fmt.Printf(\"German \\\"street\\\" - \\\"%s\\\" - length %d\\n\", germanWord, utf8.RuneCountInString(germanWord))\n", | ||
"fmt.Printf(\"Converted to uppercase - \\\"%s\\\" - length %d\\n\", germanUpper, utf8.RuneCountInString(germanUpper))\n", | ||
"fmt.Printf(\"Converted to lowercase - \\\"%s\\\" - length %d\\n\", germanLower, utf8.RuneCountInString(germanLower))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |