Coder Social home page Coder Social logo

skyem123 / stringmatcher1 Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 410 KB

A matching thing written in Kotlin, because RegEx is too painful on it's own. (and I wanted to try Kotlin). Now abandoned.

License: BSD 2-Clause "Simplified" License

Java 31.59% Kotlin 68.41%

stringmatcher1's People

Contributors

skyem123 avatar

Watchers

 avatar  avatar

stringmatcher1's Issues

Switch Matcher

Can we get a switch matcher? It's a set of key-value pairs (aka a HashMap (but not necessarily)) that is much faster than alternations (O(1) vs O(n)).

First you need a pattern. This pattern will be used to lookup a pattern in the map. After matching the pattern, and looking up the result in the map, there are 2 possible outcomes:

  • The value is null, or the key doesn't exist.
    • Check for a default case, which is set by using setCase(null, pattern). This has 2 possible outcomes:
      • If there is no default case, the match fails.
      • If there is a default case, we attempt to match it.
  • The value is not null. Attempt to match it.

Constructing and using switch matchers could be done as in switch(pattern).setCase(string, pattern).setCase(string, pattern).setCase(null, pattern).

Removing cases could be done with setCase(string, null).

Optimisation

Possible ideas:

  • Use a more efficient regex library
  • Avoid using regex for simple matchers like the EverythingMatcher

Documentation of the external API.

This is very important for a library, and it will also be good to have tutorials in this repo.

_Note that this issue will not be closed, as it is an important reminder to new code written_

Multiple matchers

Issue #15 seems like an interesting way to combine multiple matchers, but other ways of linking matchers together will also be useful.

Combining matchers with methods on the Matcher class

(Maybe the methods should use varargs to reduce the number of ( and ) needed.)

.and(Matcher)

This will do an and operation between the two matchers.
For a very simple example, matchAll().and(match("test")).useOn("this is a test") should only have one match result, which would be 10 4 test. This would also work reversed, for example match("test").and(matchAll()).useOn("this is a test") would have exactly the same result.

A more complex example of the .and(Matcher) system would be startsWith(match("this")).and(endsWith(match("hello"))).useOn("this is a test, hello world!") will have a single match result of 10 21 test, hello.

.or(Matcher)

This will do an or operation between the two matchers. For example, startsWith(match("this")).or(endsWith(match("hello"))).useOn("this is a test, hello world!") will have a single match result of 0 28 this is a test, hello world!
For a more complex example, match("test").or(match("hello")).useOn("this is a test, hello world!") will have two match results, 10 14 test and 16 21 hello.

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.