Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string functions #37

Open
18 tasks
jimscarver opened this issue May 29, 2021 · 3 comments
Open
18 tasks

Add string functions #37

jimscarver opened this issue May 29, 2021 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@jimscarver
Copy link
Collaborator

Introduction/Motivation/Abstract

develops expect standard string functions including converting other types toString()

Motivating Examples

Examples

  • S.length is the length of the string in characters;
  • S.substring(i) returns the part of the string starting at index i.
  • S.substring(i,j) returns the part of the string starting at index i and going up to index j-1. You can write S.slice(i,j) instead.
  • S.contains(T) returns true if T is a substring of S;
  • S.indexOf(T) returns the index of the first occurrence of the substring T in S (or -1);
  • S.indexOf(T, i) returns the index of the first occurrence after index i of the substring T in S (or -1);
  • S.toLowerCase and S.toUpperCase return a copy of the string with all characters converted to lower or upper case;
  • S.capitalize returns a new string with the first letter only converted to upper case;
  • S.reverse returns the string backwards;
  • S.isEmpty is the same as S.length == 0;
  • S.nonEmpty is the same as S.length != 0;
  • S.startsWith(T) returns true if S starts with T;
  • S.endsWith(T) returns true if S ends with T;
  • S.replace(c1, c2) returns a new string with all characters c1 replaced by c2;
  • S.replace(T1, T2) returns a new string with all occurrences of the substring T1 replaced by T2;
  • S.trim returns a copy of the string with white space at both ends removed;
  • S.format(arguments) returns a string where the percent-placeholders in S have been replaced by the arguments (see example below);
  • S.split(T) splits the string into pieces and returns an array with the pieces. T is a regular expression (not explained here). To split around white space, use S.split("s+").

Please check the ones we already have. This is a good first issue for someone.

Comparison Examples

I struggled to concatenate a number and a string ultimately discovering it is impossible in rholag. Nothing should be impossible in rholang.

Counter-Examples

Design

Counter-Examples

Drawbacks

Alternatives

References

@jimscarver jimscarver added the enhancement New feature or request label May 29, 2021
@jimscarver
Copy link
Collaborator Author

We also need a simple String.match capability being considered in #14

@dckc
Copy link

dckc commented Jun 10, 2021

...
I struggled to concatenate a number and a string ultimately discovering it is impossible in rholag.

Are you quite sure about that, @jimscarver ? String interpolation works when I try it in the rholang playground:

new x in {
  x!("${n}${s}" %% {"n": 123, "s": "abc"})
}

Result

[
  "123abc"
]

@jimscarver jimscarver added good first issue Good for newcomers help wanted Extra attention is needed labels Oct 23, 2021
@jimscarver
Copy link
Collaborator Author

There are many other string functions that are needed like case conversion, finding a substring, and matching patterns.

Regular expressions prove to be problematical due to recursion see #19 however filename "glob" pattern matching like [Ss]ubstring are not recursive and could be supported easily https://index.scala-lang.org/salva/scala-glob/scala-glob/0.0.3?

We can also support more types for existing functions easily like string.contains(substring). Any type that makes sense in a function should be supported. This could be done even by scala newbees

@jimscarver jimscarver changed the title add string function add string functions Oct 23, 2021
@tgrospic tgrospic changed the title add string functions Add string functions Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants