Skip to content

Commit

Permalink
Implement seek and search
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 5, 2025
1 parent ee15bbc commit 56e9ab1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/core/gossamer-core.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Gossamer, version 0.24.0. Copyright 2025 Jon Pretty, Propensive OÜ.
Gossamer, version [unreleased]. Copyright 2025 Jon Pretty, Propensive OÜ.
The primary distribution site is: https://propensive.com/
Expand Down Expand Up @@ -31,7 +31,7 @@ import vacuous.*
import scala.reflect.*
import scala.collection.mutable as scm

import java.util.regex.*
import java.util.regex as jur
import java.net.{URLEncoder, URLDecoder}

import language.experimental.pureFunctions
Expand Down Expand Up @@ -181,7 +181,11 @@ extension [TextType: Textual](text: TextType)

def contains(substring: into Text): Boolean = TextType.indexOf(text, substring).present
def contains(char: Char): Boolean = TextType.indexOf(text, char.show).present
def seek(substring: into Text): Optional[Ordinal] = TextType.indexOf(text, substring)

def search(regex: Regex, overlap: Boolean = false): LazyList[TextType] =
regex.search(TextType.text(text), overlap = overlap).map(text.segment(_))

def seek(regex: Regex): Optional[TextType] = regex.seek(TextType.text(text)).let(text.segment(_))

inline def trim: TextType =
val start = text.where(!_.isWhitespace).or(Ult.of(text))
Expand Down Expand Up @@ -282,7 +286,7 @@ extension [TextType: Textual](text: TextType)

extension (text: into Text)
inline def sub(from: into Text, to: into Text): Text =
text.s.replaceAll(Pattern.quote(from.s).nn, to.s).nn.tt
text.s.replaceAll(jur.Pattern.quote(from.s).nn, to.s).nn.tt

inline def sub(from: Regex, to: into Text): Text = text.s.replaceAll(from.pattern.s, to.s).nn.tt

Expand Down
2 changes: 1 addition & 1 deletion src/core/soundness+gossamer-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export gossamer.{Bidi, Buffer, Cuttable, Decimalizer, Interpolation, Joinable, N
snip, reverse, contains, trim, where, upto, dropWhile, snipWhere,
mapChars, count, metrics, pad, center, fit, uncamel, unkebab, unsnake, starts, ends,
tr, subscript, superscript, sub, flatMap, urlEncode, urlDecode, punycode, bytes,
sysBytes, lev, join, add, words, lines, appendln, spaced, slices}
sysBytes, lev, join, add, words, lines, appendln, spaced, slices, seek, search}

package decimalFormatters:
export gossamer.decimalFormatters.java
Expand Down

0 comments on commit 56e9ab1

Please sign in to comment.