ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
168 stars 53 forks source link

Add `string:reverse` function #1119

Open SasinduDilshara opened 2 years ago

SasinduDilshara commented 2 years ago

Description: There is no in-built function to reverse a Ballerina String. There are few other methods available

But there is no in-built function to reverse a string.

Suggested Labels:

SasinduDilshara commented 2 years ago

This document contains the string reverse functionality of other Programming Languages. https://docs.google.com/document/d/1yQu1fjvhMFSMDr1UfoC-OXVtk_mrb4I9_2clpX4Z7kw/edit?usp=sharing

jclark commented 2 years ago

The solution with toBytes/fromBytes won't work for non-ASCII characters.

What is this useful for?

Does reversing characters really make sense with Unicode combining characters? For example, if I have the letter A followed combining circumflex accent, and then reverse it, I will get a combining circumflex accent followed A, which won't be displayable sensibly. Would reversing grapheme clusters make more sense?

SasinduDilshara commented 2 years ago

This reverse method will be helpful for algorithms that use palindromes. And also reverse method will help to deal with some regular expressions efficiently.

SasinduDilshara commented 2 years ago

The solution with toBytes/fromBytes won't work for non-ASCII characters.

What is this useful for?

Does reversing characters really make sense with Unicode combining characters? For example, if I have the letter A followed combining circumflex accent, and then reverse it, I will get a combining circumflex accent followed A, which won't be displayable sensibly. Would reversing grapheme clusters make more sense?

+1 for adding functionality for reversing grapheme clusters.