šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

github.com/pschlump/pw3

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pschlump/pw3

v0.0.0-20231118131110-1b4a3f9cddfe
Source
Go
Version published
Created
Source

pw: parse words

license

This is for parsing a string into a set of words. For Example:

import (
	pw "github.com/pschlump/pw3"
)

/* ... */

func ParseLineIntoWords(line string) []string {
	Pw := pw.NewParseWords()
	Pw.SetOptions("C", false, false)
	Pw.SetLine(line)
	rv := Pw.GetWords()
	return rv
}

Will take a line like this one and return an array of words.

Examples using the above code.

	s := `set aa "{\"ab\":123}"`
	words := ParseLineIntoWords(s)
	fmt.Printf ( "%s\n", words )

Outputs in (length 3)

[set aa {"ab":123}]

2nd Example

Example using CLI input and parsing multiple lines into words.


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"

	pw "github.com/pschlump/pw3"
)

func main() {
	Pw := pw.NewParseWords()
	// Pw.SetOptions("C", false, false)  -- these are the default opsions, so skip

	scanner := bufio.NewScanner(os.Stdin)
	line_no := 0
	for scanner.Scan() {
		line_no++
		line := scanner.Text()

		Pw.SetLine(line)
		words := Pw.GetWords()

		fmt.Printf("Words len=%d: %s\n", len(words), words)
	}

	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
}

FAQs

Package last updated on 18 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts