Skip to content

Commit

Permalink
Add examples of breaking strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed May 15, 2024
1 parent 955dfac commit 1ba8ed2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
24 changes: 24 additions & 0 deletions Notebooks/1_c#_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@
"PrintUnicode('\\\"');\n",
"PrintUnicode('\\\\');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Beware of Breakage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "polyglot-notebook"
}
},
"outputs": [],
"source": [
"string str4 = \"\\uD801\\uDC00\".Substring(0, 1);\n",
"\n",
"Console.WriteLine(str4);\n",
"Console.WriteLine(\"length: \" + str4.Length);\n",
"Console.WriteLine(\"code points: \" + char.ConvertToUtf32(str4, 0));"
]
}
],
"metadata": {
Expand Down
34 changes: 27 additions & 7 deletions Notebooks/1_java_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/sualeh/What-a-Character/blob/java/Notebooks/1_java_unicode_char_literals.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
Expand Down Expand Up @@ -202,9 +202,33 @@
"printUnicode('\\\"');\n",
"printUnicode('\\\\');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Beware of Breakage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"String str4 = \"\\uD801\\uDC00\".substring(0, 1);\n",
"\n",
"System.out.println(str4);\n",
"System.out.println(\"length: \" + str4.length());\n",
"System.out.println(\"code points: \" + str4.codePointCount(0, str4.length()));"
]
}
],
"metadata": {
"colab": {
"include_colab_link": true,
"provenance": []
},
"kernelspec": {
"display_name": "Java",
"language": "java",
Expand All @@ -228,12 +252,8 @@
}
]
}
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 0
}
}
33 changes: 33 additions & 0 deletions Notebooks/1_javascript_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,28 @@
"printUnicode('\\\"');\n",
"printUnicode('\\\\');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Beware of Breakage"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%script node\n",
"\n",
"let str4 = \"\\uD801\\uDC00\".substring(0, 1);\n",
"\n",
"console.log(str4);\n",
"console.log(\"length: \" + str4.length);\n",
"console.log(\"code points: \" + Array.from(str4).length);"
]
}
],
"metadata": {
Expand All @@ -206,6 +228,17 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1ba8ed2

Please sign in to comment.