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

Adding a String library #105

Closed
EricIO opened this issue Feb 25, 2015 · 17 comments
Closed

Adding a String library #105

EricIO opened this issue Feb 25, 2015 · 17 comments

Comments

@EricIO
Copy link

EricIO commented Feb 25, 2015

(Tobias) I am changing this discussion. The new topic of this issue will be "String library".

@EricIO EricIO changed the title Operations on strings Operations on strings [feature requests / enhancement] Feb 25, 2015
@EricIO EricIO changed the title Operations on strings [feature requests / enhancement] Operations on strings [feature request / enhancement] Feb 25, 2015
@kaeluka kaeluka changed the title Operations on strings [feature request / enhancement] Operations on strings Feb 26, 2015
@TobiasWrigstad TobiasWrigstad changed the title Operations on strings Adding a String library Sep 18, 2015
@TobiasWrigstad
Copy link
Contributor

For anyone following this ticket, @EliasC and I are working on this. We have a fork where string literals actually give rise to new string objects with a semi-rich interface. This is the current, mostly self-explanatory interface of Encore strings. If you are missing a feature, please write here.

  def init(s:string) : void
  def concatenate(b:String) : String
  def copy() : String
  def contains(b:String) : bool
  def contains_ignore_case(b:String) : bool
  def compare(b:String) : int
  def compare_ignore_case(b:String) : int
  def to_upper() : String
  def to_lower() : String
  def length() : int
  def size() : int
  def get_() : String
  def substring(from:int, to:int) : String
  def format(b:[String]) : String

This work is intended to att Strings as the first library class which is loaded automatically by all programs.

@kikofernandez
Copy link
Contributor

I think the equals would be good to have

@TheGrandmother
Copy link
Contributor

having a trim method (removes leading and trailing white-spaces) would be quite nice!

@TobiasWrigstad
Copy link
Contributor

@kikofernandez: is this the intended semantics of equals?

def equals(s:string) : bool
  this.compare(s) == 0

?

@TobiasWrigstad
Copy link
Contributor

@TheGrandmother
Just whitespace? ' ' or also '\n' etc.? (Give me a spec!)

Non-destructive, I guess too?

@kikofernandez
Copy link
Contributor

Yes, that would work.

@kikofernandez: is this the intended semantics of equals?

def equals(s:string) : bool
this.compare(s) == 0
?

@TobiasWrigstad
Copy link
Contributor

Thanks!

@TheGrandmother
Copy link
Contributor

@TobiasWrigstad
Any whitespace character. Tabs and newlines included.
Where is this fork?

split_at(string,substring) and join_with(string,substring) are also nice to have.
Like so:

split_at("bob kjell glenn kjell otto", " kjell ") = ["bob","glenn","otto"]
join_with(["bob","glenn","otto"], " kjell ") = "bob kjell glenn kjell otto"

@TobiasWrigstad
Copy link
Contributor

Tack!

@TobiasWrigstad
Copy link
Contributor

FYI This is the extended String interface:

  def init(s:string) : void
  def concatenate(b:String) : String
  def copy() : String
  def contains(b:String) : bool
  def contains_ignore_case(b:String) : bool
  def compare(b:String) : int
  def compare_ignore_case(b:String) : int
  def to_upper() : String
  def to_lower() : String
  def length() : int
  def size() : int
  def get_() : String
  def substring(from:int, to:int) : String
  def equals(s:String) : bool
  def occurrences(s:String) : int
  def split(s:String) : [String]
  def join(strings:[String]) : String
  def trim() : String
  def replace(a:String, b:String) : String
  def find(a:String) : int
  def find_from(a:String, b:int) : int
  def delete(s:String) : String
  def format(b:[String]) : String

@supercooldave
Copy link

What does delete do?
Can concatenate be called concat?

@TobiasWrigstad
Copy link
Contributor

Delete removes occurrences of a string from another. It is like replace, but more efficiently implemented.
I am fine with renaming any of these.

The get_ should go — it is not needed anymore (was for getting to underlying C string).

@supercooldave
Copy link

All occurrences?

@TheGrandmother
Copy link
Contributor

What is the difference between length and size ??

@TobiasWrigstad
Copy link
Contributor

@supercooldave All occurrences.
@TheGrandmother nothing.

@TobiasWrigstad
Copy link
Contributor

@supercooldave
Slow:

  def replace(a:String, b:String) : String
    b.join(this.split(a))

Fast (might not even leave the stack for intermediate strings):

  def delete(s:String) : String
      new String(embed string
        a ton of C code
      end)

@TobiasWrigstad TobiasWrigstad added this to the plenary milestone Oct 2, 2015
@EliasC
Copy link
Contributor

EliasC commented Nov 24, 2015

Implemented as of 42c83e3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants