Skip to content
Snippets Groups Projects
Select Git revision
  • 8e6f0cdc6c82e8868071fbce6a3d8fa955e7769a
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

string_utils.go

Blame
  • string_utils.go 8.65 KiB
    package string_utils
    
    import (
    	"bytes"
    	"encoding/json"
    	"fmt"
    	"github.com/samber/lo"
    	"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/number_utils"
    	"regexp"
    	"strconv"
    	"strings"
    	"unicode"
    
    	"github.com/thoas/go-funk"
    	"golang.org/x/text/runes"
    	"golang.org/x/text/transform"
    	"golang.org/x/text/unicode/norm"
    )
    
    const (
    	snakeCasePattern = `[a-z]([a-z0-9_]*[a-z0-9])*`
    
    	regexIndexMatchStart    = 0
    	regexIndexMatchEnd      = 1
    	regexIndexSubmatchStart = 2
    	regexIndexSubmatchEnd   = 3
    )
    
    var WhitespaceChars = []string{
    	// Standard whitespace characters
    	"\u0009", // Character tabulation
    	"\u000A", // Line feed
    	"\u000B", // Line tabulation
    	"\u000C", // Form feed
    	"\u000D", // Carriage return
    	"\u0020", // Space
    	"\u0085", // Next line
    	"\u00A0", // No-break space
    	"\u1680", // Ogham space mark
    	"\u2000", // En quad
    	"\u2001", // Em quad
    	"\u2002", // En space
    	"\u2003", // Em space
    	"\u2004", // Three-per-em space
    	"\u2005", // Four-per-em space
    	"\u2006", // Six-per-em space
    	"\u2007", // Figure space
    	"\u2008", // Punctuation space
    	"\u2009", // Thin space
    	"\u200A", // Hair space
    	"\u2028", // Line separator
    	"\u2029", // Paragraph separator
    	"\u202F", // Narrow no-break space
    	"\u205F", // Medium mathematical space
    	"\u3000", // Ideographic space
    }
    
    var NonOfficialWhitespaceChars = []string{
    	// Characters with property White_Space=no
    	"\u180E", // Mongolian vowel separator
    	"\u200B", // Zero width space
    	"\u200C", // Zero width non-joiner
    	"\u200D", // Zero width joiner
    	"\u2060", // Word joiner
    	"\u202C", // Pop directional formatting
    	"\uFEFF", // Zero width no-break space
    	"\u00AD", // Soft hyphen
    }
    
    var snakeCaseRegex = regexp.MustCompile("^" + snakeCasePattern + "$")