From 4c45eb9fb377e9dbdf55ab4894e80f11379ce8dd Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 7 Feb 2020 05:27:23 -0800 Subject: [PATCH 1/2] Add string reference page to docs --- gitlab-pages/docs/reference/string.md | 81 +++++++++++++++++++++++++++ src/test/md_file_tests.ml | 1 + 2 files changed, 82 insertions(+) create mode 100644 gitlab-pages/docs/reference/string.md diff --git a/gitlab-pages/docs/reference/string.md b/gitlab-pages/docs/reference/string.md new file mode 100644 index 000000000..84d54cfd2 --- /dev/null +++ b/gitlab-pages/docs/reference/string.md @@ -0,0 +1,81 @@ +--- +id: string-reference +title: String +--- + +## String.size(s: string) : nat + +Get the size of a string. [Michelson only supports ASCII strings](http://tezos.gitlab.io/whitedoc/michelson.html#constants) +so for now you can assume that each character takes one byte of storage. + + + + +```pascaligo +function string_size (const s: string) : nat is size(s) +``` + + +```cameligo +let size_op (s: string) : nat = String.size s +``` + + +```reasonligo +let size_op = (s: string): nat => String.size(s); +``` + + + +## String.length(s: string) : nat + +Alias for `String.size`. + +## String.slice(pos1: nat, pos2: nat, s: string) : string + +Get the substring of `s` between `pos1` inclusive and `pos2` inclusive. For example +the string "tata" given to the function below would return "at". + + + +```pascaligo +function slice_op (const s : string) : string is + begin skip end with string_slice(1n , 2n , s) +``` + +```cameligo +let slice_op (s: string) : string = String.slice 1n 2n s +``` + +```reasonligo +let slice_op = (s: string): string => String.slice(1n, 2n, s); +``` + + +## String.sub(pos1: nat, pos2: nat, s: string) : string + +Alias for `String.slice`. + +## String.concat(s1: string, s2: string) : string + +Concatenate two strings and return the result. + + + + +```pascaligo +function concat_op (const s : string) : string is + begin skip end with string_concat(s , "toto") +``` + + +```cameligo +let concat_syntax (s: string) = s ^ "test_literal" +``` + + +```reasonligo +let concat_syntax = (s: string) => s ++ "test_literal"; +``` + + diff --git a/src/test/md_file_tests.ml b/src/test/md_file_tests.ml index 86aefeb89..f697a18d4 100644 --- a/src/test/md_file_tests.ml +++ b/src/test/md_file_tests.ml @@ -122,6 +122,7 @@ let md_files = [ "/gitlab-pages/docs/advanced/timestamps-addresses.md"; "/gitlab-pages/docs/api/cli-commands.md"; "/gitlab-pages/docs/api/cheat-sheet.md"; + "/gitlab-pages/docs/reference/string.md"; ] let md_root = "../../gitlab-pages/docs/language-basics/" From 02c59db8b8d5b2d8b1189949d23d44468470a18f Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 7 Feb 2020 14:03:57 -0800 Subject: [PATCH 2/2] Simplify a few pascaligo functions in string reference page --- gitlab-pages/docs/reference/string.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gitlab-pages/docs/reference/string.md b/gitlab-pages/docs/reference/string.md index 84d54cfd2..4b64bbc4b 100644 --- a/gitlab-pages/docs/reference/string.md +++ b/gitlab-pages/docs/reference/string.md @@ -39,8 +39,7 @@ the string "tata" given to the function below would return "at". ```pascaligo -function slice_op (const s : string) : string is - begin skip end with string_slice(1n , 2n , s) +function slice_op (const s : string) : string is string_slice(1n , 2n , s) ``` ```cameligo @@ -64,8 +63,7 @@ Concatenate two strings and return the result. ```pascaligo -function concat_op (const s : string) : string is - begin skip end with string_concat(s , "toto") +function concat_op (const s : string) : string is s ^ "toto" ```