All Projects → dfinke → PSStringScanner

dfinke / PSStringScanner

Licence: MIT license
Provides lexical scanning operations on a String

Programming Languages

powershell
5483 projects

Projects that are alternatives of or similar to PSStringScanner

Jflex
The fast scanner generator for Java™ with full Unicode support
Stars: ✭ 380 (+744.44%)
Mutual labels:  parsing, scanner
tokenizr
String Tokenization Library for JavaScript
Stars: ✭ 70 (+55.56%)
Mutual labels:  parsing, string
kataw
An 100% spec compliant ES2022 JavaScript toolchain
Stars: ✭ 303 (+573.33%)
Mutual labels:  parsing
Laser-XY-Scanner
Low Cost DIY Laser XY Scanner, Cutter, or Engraver
Stars: ✭ 27 (-40%)
Mutual labels:  scanner
Concrete-Syntax-Tree
Concrete Syntax Trees represent s-expressions with source information
Stars: ✭ 48 (+6.67%)
Mutual labels:  parsing
sec-scannode
SEC分布式资产扫描系统
Stars: ✭ 8 (-82.22%)
Mutual labels:  scanner
cvscan
Your not so typical resume parser
Stars: ✭ 46 (+2.22%)
Mutual labels:  parsing
yandi-scanner
Network Security Vulnerability Scanner
Stars: ✭ 110 (+144.44%)
Mutual labels:  scanner
jfreesane
Java API to talk to the SANE scanning daemon
Stars: ✭ 46 (+2.22%)
Mutual labels:  scanner
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+26.67%)
Mutual labels:  parsing
memology
Memes - why so popular?
Stars: ✭ 32 (-28.89%)
Mutual labels:  parsing
core
An advanced and highly optimized Java library to build frameworks: it's useful for scanning class paths, generating classes at runtime, facilitating the use of reflection, scanning the filesystem, executing stringified source code and much more...
Stars: ✭ 100 (+122.22%)
Mutual labels:  scanner
Compiler-written-in-Haskell
A Turing complete language 😉
Stars: ✭ 31 (-31.11%)
Mutual labels:  parsing
sixarm ruby unaccent
SixArm.com » Ruby » Unaccent replaces a string's accented characters with ASCII characters.
Stars: ✭ 15 (-66.67%)
Mutual labels:  string
docus
Android application for scanning and managing documents.
Stars: ✭ 39 (-13.33%)
Mutual labels:  scanner
http-accept
Parse Accept and Accept-Language HTTP headers in Ruby.
Stars: ✭ 69 (+53.33%)
Mutual labels:  parsing
split-on-first
Split a string on the first occurrence of a given separator
Stars: ✭ 68 (+51.11%)
Mutual labels:  string
Document-Scanner-and-OCR
A simple document scanner with OCR implemented using Python and OpenCV
Stars: ✭ 31 (-31.11%)
Mutual labels:  scanner
log4j-detector
Log4J scanner that detects vulnerable Log4J versions (CVE-2021-44228, CVE-2021-45046, etc) on your file-system within any application. It is able to even find Log4J instances that are hidden several layers deep. Works on Linux, Windows, and Mac, and everywhere else Java runs, too!
Stars: ✭ 622 (+1282.22%)
Mutual labels:  scanner
bracer
Java library for parsing and evaluating math expressions
Stars: ✭ 18 (-60%)
Mutual labels:  parsing

PowerShell String Scanner

Provides lexical scanning operations on a String.

Ported from https://github.com/ruby/strscan

Parsing a Config File

Usage

$scanner = New-PSStringScanner 'This is an example string'

$scanner.EoS()               # -> False
$scanner.Scan("\w+")         # 'This'
$scanner.Scan("\s+")         # ' '
$scanner.Scan("\w+")         # 'is'
$scanner.EoS()               # -> False
$scanner.Scan("\s+")         # ' '
$scanner.Scan("\w+")         # 'an'
$scanner.Scan("\s+")         # ' '
$scanner.Scan("\w+")         # 'example'
$scanner.Scan("\s+")         # ' '
$scanner.Scan("\w+")         # 'string'
$scanner.EoS()               # -> True

More Uses

Two approaches, same results.

Using Scan, Check and Skip

$scanner = New-PSStringScanner 'Eggs, cheese, onion, potato, peas'

$actualItems = @()
while ($true) {
    $actualItems += $scanner.scan("\w+")
    if ($scanner.Check(',')) {
        $scanner.Skip(',\s*')
    }
    else {
        break
    }
}

Using Do {} Until

$scanner = New-PSStringScanner 'Eggs, cheese, onion, potato, peas'

$actualItems = do {$scanner.scan("\w+")} until ($scanner.EoS())

ScanUntil

Scans the string until the pattern is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, null is returned.

$scanner = New-PSStringScanner 'Fri Dec 12 1975 14:39'

$scanner.ScanUntil("1")   # "Fri Dec 1"
$scanner.ScanUntil("YYZ") # $null

CheckUntil

This returns the value that ScanUntil would return, without advancing the scan pointer. The match register is affected, though.

$scanner = New-PSStringScanner 'Fri Dec 12 1975 14:39'

$scanner.CheckUntil("12")   # "Fri Dec 12"
$scanner.pos                # 0

SkipUntil

Advances the scan pointer until pattern is matched and consumed. Returns the number of bytes advanced, or null if no match was found.

Look ahead to match pattern, and advance the scan pointer to the end of the match. Return the number of characters advanced, or null if the match was unsuccessful.

It's similar to ScanUntil, but without returning the intervening string.

$scanner = New-PSStringScanner 'Fri Dec 12 1975 14:39'

$scanner.SkipUntil("12")   # 10
$scanner
# s                     pos
# -                     ---
# Fri Dec 12 1975 14:39  10
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].