Skip to content

A very fast implementation of a Lexical Tokeniser that allows for replacing of and escaping of special characters to be replaced i.e. [Tag] <Tag> or {Tag} become the value provided in the dictionary under the key Tag. Very fast (863 ns/op, 312 B/op, 11 allocs/op) vs Regex (9035 ns/op, 10831 B/op, 116 allocs/op)

License

Notifications You must be signed in to change notification settings

CADawg/Lexical-Tokeniser-Tag-Replacement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lexical Tokeniser Tag Replacement

Replaces tags i.e. [tag], {tag} and <tag> with the corresponding tag value provided in a dictionary.

Install

go get -u github.com/CADawg/Lexical-Tokeniser-Tag-Replacement

Usage

package main

import (
    "fmt"
    "github.com/CADawg/Lexical-Tokeniser-Tag-Replacement"
)

func main() {
    tags := map[string]string{
        "tag1": "value1",
        "tag2": "value2",
    }

    text := "This is a [tag1] and this is a {tag2} and this is a <tag3> [tag3] and this is an [[escaped tag]."

    replacedText := LexicalTokeniserTagReplacement.ReplaceTagsInString(text, tags)

    fmt.Println(replacedText)
    
    // prints: This is a value1 and this is a value2 and this is a <ERROR:tag3> [ERROR:tag3] and this is an [escaped tag].
    // will show <error:tag name> if the tag is not found in the tags dictionary
    // using [[, {{ or << will escape the tag and not replace it.
}

About

A very fast implementation of a Lexical Tokeniser that allows for replacing of and escaping of special characters to be replaced i.e. [Tag] <Tag> or {Tag} become the value provided in the dictionary under the key Tag. Very fast (863 ns/op, 312 B/op, 11 allocs/op) vs Regex (9035 ns/op, 10831 B/op, 116 allocs/op)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages