Giter VIP home page Giter VIP logo

substring's People

Contributors

anders429 avatar dependabot-preview[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xack13

substring's Issues

len shorthand

Should be able to exclude len() for example:

string.substring_len(3)

Could be a shorthand for string.substring(3, string.len())

Support Different Kinds of Substrings

There are different kinds of substrings that can be supported by this library. Currently, the implementation supports substrings with respect to chars, but some users will likely want substrings with respect to graphemes instead. Word and sentence substrings could also be supported using the relevant unicode standards.

Altogether, I see the following substring variants being possible:

  • CharSubstring: respect to chars, which are unicode scalar values.
  • GraphemeSubstring: respect to graphemes (using unicode-segmentation).
  • WordSubstring: respect to words (using unicode-segmentation).
  • SentenceSubstring: respect to sentences (using unicode-segmentation).
  • ByteSubstring: respecting individual bytes (equivalent to slicing the string).

Since we are already looking at a breaking change with #9, the Substring trait can be renamed to CharSubstring (so there is no ambiguity between substring variants). The unicode-segmentation variants (grapheme, word, and sentence) can be guarded behind a unicode feature (or perhaps separate features for each?). The byte variant can be held off on for now, since it really isn't needed and presents issues with properly-formed strings.

This solution will give maximum clarity as to what this crate offers, and will give flexibility for users to choose from the various types of substrings offered.

Use RangeBounds<usize> instead of usize.

The parameters for the substring method can be changed to a RangeBounds. This will allow for providing inclusive end points, as well as providing unbounded start/end points (as has been requested in #5).

This would be a breaking change, but I think it will make the library a bit easier to use. I would rather do this than introduce several methods for each specific case. It will also raise MSRV to match what is required for RangeBounds.

Negative indexing

Support for negative indexing would be helpful.

Example:

string.substring(-5, -3)

On the string "hello world" this would return "wo".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.