strops

package module
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package strops - (string operations) provides string management utilities designed to perform a variety of string operations including string centering, justification, multiple replacements numeric and date field extraction as well as implementing the io.Reader and io.Writer interfaces.

Source files for package 'strops' are located in source code repository:

https://github.com/MikeAustin71/stringopsgo.git

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataFieldProfileDto added in v2.0.4

type DataFieldProfileDto struct {
	TargetStr                      string                         //  The string from which the data field  is extracted.
	TargetStrLength                int                            //  Length of 'TargetStr'.
	TargetStrStartIndex            int                            //  The index with in 'TargetStr' from which the search for a data field was initiated.
	TargetStrLastGoodIndex         int                            //  Last valid index in target string which is less than the target string length and is NOT an 'End Of Field' or 'End Of Line' Delimiter.
	LeadingKeyWordDelimiter        string                         //  The Leading Key Word Delimiter which is used to identify the beginning of the field search.
	LeadingKeyWordDelimiterIndex   int                            //  Index of the found Leading Key Word Delimiter
	DataFieldStr                   string                         //  The extracted data field string
	DataFieldIndex                 int                            //  The index in 'TargetStr' where the data field begins.
	DataFieldLength                int                            //  The length of the extracted data field string.
	DataFieldTrailingDelimiter     string                         //  The trailing character which marked the end of the data field. A zero value indicates end of string encountered.
	DataFieldTrailingDelimiterType DataFieldTrailingDelimiterType //  A constant or enumeration type used to describe the type of delimiter used to mark the end of a data field.
	NextTargetStrIndex             int                            //  The index in 'TargetStr' immediately following the extracted data field.
	CommentDelimiter               string                         //  If a Comment Delimiter is detected it is stored here.
	CommentDelimiterIndex          int                            //  If a Comment Delimiter is detected, the string index in 'TargetStr' showing its location is stored here.
	EndOfLineDelimiter             string                         //  If an End-Of-Line Delimiter is detected it is captured and stored here.
	EndOfLineDelimiterIndex        int                            //  If an End-Of-Line Delimiter is detected, the string index in 'TargetStr' showing its location is stored here.
}

DataFieldProfileDto - This type is used to encapsulate information related to an extracted data field string.

func (*DataFieldProfileDto) ConvertToErrorState added in v2.0.4

func (dfProfile *DataFieldProfileDto) ConvertToErrorState()

ConvertToErrorState - Prepares the current DataFieldProfileDto instance for return as part of an error or null state condition. All references to the data field are zeroed.

func (DataFieldProfileDto) New added in v2.0.4

func (dfProfile DataFieldProfileDto) New() DataFieldProfileDto

New - Creates and returns a new instance of DataFieldProfileDto containing properly initialized internal data fields.

type DataFieldTrailingDelimiterType added in v2.0.4

type DataFieldTrailingDelimiterType int

DataFieldTrailingDelimiterType - Enumerates the type of delimiters used to mark the end of a a data field within a host string.

DataFieldTrailingDelimiterType has been adapted to function as an enumeration of valid Data Field Delimiter Types. Since Go does not directly support enumerations, the 'DataFieldTrailingDelimiterType' has been configured to function in a manner similar to classic enumerations found in other languages like C#. For additional information, reference:

Jeffrey Richter Using Reflection to implement enumerated types
       https://www.youtube.com/watch?v=DyXJy_0v0_U

Valid Enumerations for DataFieldTrailingDelimiterType are invoked by calling the appropriate method on this type:

DataFieldTrailingDelimiterType(0).Unknown()
DataFieldTrailingDelimiterType(0).EndOfField()
DataFieldTrailingDelimiterType(0).Comment()
DataFieldTrailingDelimiterType(0).EndOfLine()
DataFieldTrailingDelimiterType(0).EndOfString()

Alternatively the shorthand method of invoking this enumeration may be employed as follows:

  DfTrailDelimiter.Unknown()
  DfTrailDelimiter.EndOfField()
  DfTrailDelimiter.Comment()
  DfTrailDelimiter.EndOfLine()
  DfTrailDelimiter.EndOfString()

Note: The variable DfTrailDelimiter is discussed below.
var DfTrailDelimiter DataFieldTrailingDelimiterType

DfTrailDelimiter - public global variable of type DataFieldTrailingDelimiterType.

This variable serves as an easier, short hand technique for accessing DataFieldTrailingDelimiterType values.

Usage:

DfTrailDelimiter.Unknown()
DfTrailDelimiter.EndOfField()
DfTrailDelimiter.Comment()
DfTrailDelimiter.EndOfLine()
DfTrailDelimiter.EndOfString()

func (DataFieldTrailingDelimiterType) Comment added in v2.0.4

Comment - The Data Field is terminated by a trailing 'comment' separator.

func (DataFieldTrailingDelimiterType) EndOfField added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) EndOfField() DataFieldTrailingDelimiterType

EndOfField - The Data Field is terminated by a trailing end of field separator.

func (DataFieldTrailingDelimiterType) EndOfLine added in v2.0.4

EndOfLine - The Data Field is terminated by a designated end-of-line separator. Often this is a designated new line character such as '\n'.

func (DataFieldTrailingDelimiterType) EndOfString added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) EndOfString() DataFieldTrailingDelimiterType

EndOfString - No specific character terminated the data field. The next character after the data field represents the end of the host string.

func (DataFieldTrailingDelimiterType) ParseString added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) ParseString(
	valueString string,
	caseSensitive bool) (DataFieldTrailingDelimiterType, error)

ParseString - Receives a string and attempts to match it with the string value of the supported enumeration. If successful, a new instance of TimeZoneClass is returned set to the value of the associated enumeration.

This is a standard utility method and is not part of the valid enumerations for this type.

------------------------------------------------------------------------

Input Parameters:

valueString   string - A string which will be matched against the
                       enumeration string values. If 'valueString'
                       is equal to one of the enumeration names, this
                       method will proceed to successful completion

caseSensitive   bool - If 'true' the search for enumeration names
                       will be case sensitive and will require an
                       exact match. Therefore, 'valid' will NOT
                       match the enumeration name, 'Valid'.

                       If 'false' a case insensitive search is
                       conducted for the enumeration name. In
                       this case, 'valid' will match the
                       enumeration name 'Valid'.

------------------------------------------------------------------------

Return Values:

DataFieldTrailingDelimiterType  - Upon successful completion, this method will return a new
                                  instance of DataFieldTrailingDelimiterType set to the value
                                  of the enumeration matched by the string search performed on
                                  input parameter,'valueString'.

error                           - If this method completes successfully, the returned error
                                  Type is set equal to 'nil'. If an error condition is encountered,
                                  this method will return an error Type which encapsulates an
                                  appropriate error message.

------------------------------------------------------------------------

Usage:

t, err := DataFieldTrailingDelimiterType(0).ParseString("EndOfLine", true)
                          OR
t, err := DataFieldTrailingDelimiterType(0).ParseString("EndOfLine()", true)
                          OR
t, err := DataFieldTrailingDelimiterType(0).ParseString("endofline", false)

For all of the cases shown above,
t is now equal to DataFieldTrailingDelimiterType(0).EndOfLine()

func (DataFieldTrailingDelimiterType) StatusIsValid added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) StatusIsValid() error

StatusIsValid - If the value of the current DataFieldTrailingDelimiterType instance is 'invalid', this method will return an error.

If the DataFieldTrailingDelimiterType is instance is 'valid', this method will return a value of 'nil'.

This is a standard utility method and is not part of the valid enumerations for this type.

func (DataFieldTrailingDelimiterType) String added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) String() string

String - Returns a string with the name of the enumeration associated with this instance of 'DataFieldTrailingDelimiterType'.

This is a standard utility method and is not part of the valid enumerations for this type.

------------------------------------------------------------------------

Return Value:

string - The string label or description for the current enumeration
         value. If, the DataFieldTrailingDelimiterType value is invalid,
         this method will return an empty string.

------------------------------------------------------------------------

Usage

t:= DataFieldTrailingDelimiterType(0).EndOfLine()
str := t.String()
    str is now equal to "EndOfLine"

func (DataFieldTrailingDelimiterType) Unknown added in v2.0.4

Unknown - Data Field Trailing Delimiter Type is unknown or undetermined.

func (DataFieldTrailingDelimiterType) Value added in v2.0.4

func (dfTrailDelimiter DataFieldTrailingDelimiterType) Value() int

Value - Returns the value of the DataFieldTrailingDelimiterType instance as type int.

type NumStrProfileDto added in v2.0.4

type NumStrProfileDto struct {
	TargetStr          string //  The original target string which is scanned for a number string.
	StartIndex         int    //  The starting index in 'TargetStr' from which the number string search was initiated.
	LeadingSignIndex   int    //  The string index of a leading sign in 'NumStr' below. If a leading sign character is NOT present in 'NumStr' this value is set to -1.
	LeadingSignChar    string //  If a leading sign character (plus '+' or minus '-') exists in data field 'NumStr' (below), it is stored in this string.
	FirstNumCharIndex  int    //  The index in 'TargetStr' (above) where the first character of the extracted number string is located.
	NextTargetStrIndex int    //  The index of the next character in 'TargetStr' immediately following the extracted number string. If no number string is identified or the next index in 'TargetStr' is invalid, the value is set to -1.
	NumStrLen          int    //  The length of the extracted number string. If a number string is not located, this value is set to -1.
	NumStr             string //  The number string extracted from 'TargetStr'.
}

NumStrProfileDto - This type is used to encapsulate information on strings of numeric digits which are extracted from larger strings.

func (NumStrProfileDto) New added in v2.0.4

func (exNumDto NumStrProfileDto) New() NumStrProfileDto

New - Creates and returns a new instance of NumStrProfileDto which is properly initialized.

type SortStrLengthHighestToLowest added in v2.0.3

type SortStrLengthHighestToLowest []string

SortStrLengthHighestToLowest - Uses to perform two level sort on string arrays. The strings are first sorted by string length (greatest length to Lowest length) and then by alphabetic sort.

This type is designed to be used in conjunction with 'sort.Sort()' Reference the Go Sort Package:

https://golang.org/pkg/sort/#Sort

Example Usage:

badChars := []string {
 "aaaaa",
 "bbbbb",
 "cccccccccc",
 "z",
 "fffffffffff",
 "xx",
 "ddddddddd",
 "eeeeeeeeeee" }

  SortStrLengthLowestToHighest(badChars)

  Output:

     ================================
     Sort by Length Highest To Lowest
     Ordered List
     ================================

     1. fffffffffff
     2. eeeeeeeeeee
     3. cccccccccc
     4. ddddddddd
     5. bbbbb
     6. aaaaa
     7. xx
     8. z

func (SortStrLengthHighestToLowest) Len added in v2.0.3

func (sortStrLenHigh SortStrLengthHighestToLowest) Len() int

Len - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

func (SortStrLengthHighestToLowest) Less added in v2.0.3

func (sortStrLenHigh SortStrLengthHighestToLowest) Less(i, j int) bool

Less - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

func (SortStrLengthHighestToLowest) Swap added in v2.0.3

func (sortStrLenHigh SortStrLengthHighestToLowest) Swap(i, j int)

Swap - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

type SortStrLengthLowestToHighest added in v2.0.3

type SortStrLengthLowestToHighest []string

SortStrLengthLowestToHighest - Uses to perform two level sort on string arrays. The strings are first sorted by string length (smallest length to greatest length) and then by alphabetic sort.

This type is designed to be used in conjunction with 'sort.Sort()' Reference the Go Sort Package:

https://golang.org/pkg/sort/#Sort

Example Usage:

  badChars := []string {
"aaaaa",
"bbbbb",
"cccccccccc",
"z",
"fffffffffff",
"xx",
"ddddddddd",
"eeeeeeeeeee" }

 SortStrLengthLowestToHighest(badChars)

 Output:

   ================================
   Sort by Length Lowest To Highest
   Ordered List
   ================================
   1. z
   2. xx
   3. aaaaa
   4. bbbbb
   5. ddddddddd
   6. cccccccccc
   7. eeeeeeeeeee
   8. fffffffffff

func (SortStrLengthLowestToHighest) Len added in v2.0.3

func (sortStrLenLow SortStrLengthLowestToHighest) Len() int

Len - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

func (SortStrLengthLowestToHighest) Less added in v2.0.3

func (sortStrLenLow SortStrLengthLowestToHighest) Less(i, j int) bool

Less - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

func (SortStrLengthLowestToHighest) Swap added in v2.0.3

func (sortStrLenLow SortStrLengthLowestToHighest) Swap(i, j int)

Swap - This is part of the sort.Interface. Reference the 'sort' package:

https://golang.org/pkg/sort/#Interface
https://golang.org/pkg/sort/#Sort

type StrOps

type StrOps struct {
	StrIn  string // public string variable available at user's discretion
	StrOut string // public string variable available at user's discretion
	// contains filtered or unexported fields
}

StrOps - encapsulates a collection of methods used to manage string operations.

Most of the utility offered by this type is provided through its associated methods. However, given that two data elements, 'StrIn' and 'StrOut' are provided, the structure may be used as a data transport object (dto) containing two strings.

Version 2.0.0 and all later versions of this type support Go Modules. For Version 2+ implementations, use the following import statement:

import "github.com/MikeAustin71/stringopsgo/strops/v2"

Earlier Version 1.0.0 implementations require a different import statement:

import "github.com/MikeAustin71/stringopsgo/strops"

Be advised that this type, 'StrOps', implements the io.Reader and io.Writer interfaces. All io.Reader and io.Writer operations utilize the private string data element, 'StrOps.stringData'.

func (StrOps) BreakTextAtLineLength

func (sops StrOps) BreakTextAtLineLength(
	targetStr string,
	lineLength int,
	lineDelimiter rune) (string, error)

BreakTextAtLineLength - Breaks string text into lines. Takes a string and inserts a line delimiter character (a.k.a 'rune') at the specified line length ('lineLength').

------------------------------------------------------------------------

Input Parameters

targetStr  string  - The string which will be parsed into text lines. If
                       'targetStr' is an empty string an error will be
                       returned. If 'targetStr' consists entirely of white
                       space, this method will return a string consisting
                       of a new-line character and an error value of 'nil'.

lineLength    int  - The maximum length of each line.

Note: If the caller specifies a line length of 50, the line delimiter character may be placed in the 51st character position depending upon the word breaks.

func (StrOps) ConvertNonPrintableChars added in v2.0.4

func (sops StrOps) ConvertNonPrintableChars(
	nonPrintableChars []rune, convertSpace bool) (printableChars string)

ConvertNonPrintableChars - Receives a string containing non-printable characters and converts them to 'printable' characters returned in a string.

If the input parameter 'convertSpace' is set to 'true' then all spaces are converted to "[SPACE]" in the returned string.

Reference:

https://www.juniper.net/documentation/en_US/idp5.1/topics/reference/general/intrusion-detection-prevention-custom-attack-object-extended-ascii.html

func (*StrOps) CopyIn

func (sops *StrOps) CopyIn(strops2 *StrOps)

CopyIn - Copies string information from another StrOps instance passed as an input parameter to the current StrOps instance.

func (*StrOps) CopyOut

func (sops *StrOps) CopyOut() *StrOps

CopyOut - Creates a 'deep' copy of the current StrOps instance and returns a pointer to a new instance containing that copied information.

func (StrOps) DoesLastCharExist

func (sops StrOps) DoesLastCharExist(testStr string, lastChar rune) bool

DoesLastCharExist - returns true if the last character (rune) of input string 'testStr' is equal to input parameter 'lastChar' which is of type 'rune'.

func (StrOps) ExtractDataField added in v2.0.4

func (sops StrOps) ExtractDataField(
	targetStr string,
	leadingKeyWordDelimiters []string,
	startIdx int,
	leadingFieldSeparators []string,
	trailingFieldSeparators []string,
	commentDelimiters []string,
	endOfLineDelimiters []string) (DataFieldProfileDto, error)

ExtractDataField - Extracts a data field string from a larger target string ('targetStr'). The target string is searched for a data field. If the 'leadingKeyWordDelimiter' parameter is populated, the data field MUST contain this leading key word, otherwise an empty data field is returned.

If 'leadingKeyWordDelimiter' is an empty string, the search for the data field will begin at 'targetStr' index, 'startIdx'.

The returned data field must occur in 'targetStr' prior to a comment or End-Of-Line character.

The extracted data field MUST be preceded by one of the characters specified in input parameter, 'leadingFieldSeparators'. In addition, the data field must be immediately followed by one of the characters in input parameter 'trailingFieldSeparators' or a comment or an End-Of-Line character.

------------------------------------------------------------------------

Input Values

targetStr               string   - The target string from which the data field will be extracted.

leadingKeyWordDelimiters []string- Data fields are often preceded by field names or field designators.
                                     The 'leadingKeyWordDelimiters' parameter is a string array
                                     containing 'Key Word Delimiters'. A Key Word Delimiter may be
                                     a Key Word string or a character which identifies and immediately
                                     precedes the data field. If multiple Key Word Delimiters exist
                                     in 'targetStr' the first instance of a key word in targetStr'
                                     will be designated as the Key Word Delimiter.

                                     If this parameter is populated, the search for a data field
                                     will begin immediately after the first located Key Word
                                     Delimiter string. If none of Key Words in this string array
                                     are located in 'targetStr', an empty string will be returned
                                     for data field. If this parameter is populated, at least one
                                     of the Key Words MUST exist in 'targetStr' before a data field
                                     will be extracted and returned.

                                     If this parameter is an empty string array, the search for a
                                     data field will begin at the string index designated by
                                     parameter, 'startIdx'.

startIdx                int      - The string index in parameter 'targetStr' from which the search for
                                     a data field will begin. Note that the starting index will be adjusted
                                     according to the existence of a Key Word Delimiter as explained
                                     above.

leadingFieldSeparators  []string - An array of characters or groups of characters which delimit the
                                     leading edge of the data field.

trailingFieldSeparators []string - An array of characters or groups of characters which delimit the
                                     end of a data field.

commentDelimiters       []string - Comments effectively terminate the search for a data field. This
                                     array stores comment characters or phrases which signal the beginning
                                     of a comment.

endOfLineDelimiters     []string - Those characters or groups of characters which mark the end of a line.
                                     Generally this includes characters like 'new line' or 'carriage return'.
                                     End of line characters will terminate the search for a data field.

------------------------------------------------------------------------

Return Values

DataFieldProfileDto - If successful, this method returns a structure containing
                      characteristics describing the extracted data field.

  type DataFieldProfileDto struct {
     TargetStr                      string //  The string from which the data field is extracted.
     TargetStrLength                int    //  Length of 'TargetStr'
     TargetStrStartIndex            int    //  The index with in 'TargetStr' from which the search for a data field was initiated.
     TargetStrLastGoodIndex         int    //  Last valid index in target string which is less than the target string length and is NOT an 'End Of Field' or 'End Of Line' Delimiter.
     LeadingKeyWordDelimiter        string //  The Leading Key Word Delimiter which is used to identify the beginning of the field search.
     LeadingKeyWordDelimiterIndex   int    //  Index of the found Leading Key Word Delimiter.
     DataFieldStr                   string //  The extracted data field string.
     DataFieldIndex                 int    //  The index in 'TargetStr' where the data field begins.
     DataFieldLength                int    //  The length of the extracted data field string.
     DataFieldTrailingDelimiter     string //  The trailing character which marked the end of the data field. A zero value indicates end of string encountered.
     DataFieldTrailingDelimiterType DataFieldTrailingDelimiterType // A constant or enumeration type used to describe the type of delimiter used to mark the end of a data field.
     NextTargetStrIndex             int    //  The index in 'TargetStr' immediately following the extracted data field.
     CommentDelimiter               string //  If a Comment Delimiter is detected it is stored here.
     CommentDelimiterIndex          int    //  If a Comment Delimiter is detected, the string index in 'TargetStr' showing its location is stored here.
     EndOfLineDelimiter             string //  If an End-Of-Line Delimiter is detected it is captured and stored here.
     EndOfLineDelimiterIndex        int    //  If an End-Of-Line Delimiter is detected, the string index in 'TargetStr' showing its location is stored here.
   }

 error              - If the method completes successfully and no errors are encountered
                      this return value is set to 'nil'. Otherwise, if errors are encountered
                      this return value will contain an appropriate error message.

                      The most likely source of errors are invalid input parameters.
                      Input parameters 'targetStr', 'startIdx', 'leadingFieldSeparators',
                      'trailingFieldSeparators' and 'endOfStringDelimiters' are required input
                      parameters and must be populated with valid data.

func (StrOps) ExtractNumericDigits added in v2.0.4

func (sops StrOps) ExtractNumericDigits(
	targetStr string,
	startIndex int,
	keepLeadingChars string,
	keepInteriorChars string,
	keepTrailingChars string) (NumStrProfileDto, error)

ExtractNumericDigits - Examines an input parameter 'targetStr' to identify and extract the first instance of a number string. The number string will be comprised of one or more consecutive numeric digits (0-9) and may include leading, trailing or interior non-numeric characters as specified by input parameters.

The search for this number string will be started at the index specified by input parameter 'startIdx'. Beginning at 'startIdx' the 'targetStr' will be searched to identify and extract the first instance of a number string.

A number string is usually defined a string of consecutive numeric digits. However, this method allows the caller to include additional non-numeric characters as identified by input parameters 'keepLeadingChars', 'keepInteriorChars' and 'keepTrailingChars'.

'keepLeadingChars' is a string of characters which will be prefixed to the number string if those characters exist in 'targetStr' and immediately precede the number string.

'keepInteriorChars' is a string of characters which, if they exist within the number string, will be retained and presented in the final extracted number string.

'keepTrailingChars' is a string of characters which will be suffixed to the end of the final extracted number string. To qualify, the designated 'keepTrailingChars' must immediately follow the number string contained in 'targetStr'.

If successfully located within 'targetStr' the first instance of a number string along with characteristics describing that number string are returned in a Type 'NumStrProfileDto'.

------------------------------------------------------------------------

Input Parameters

targetStr           string    - The target string to be searched for the first instance of
                                a number string. A number string is usually defined as a
                                string comprised of one or more consecutive numeric digits.
                                Additional parameters provided by this method will allow
                                the caller to insert specified non-numeric characters at
                                the beginning, end or interior of a number string.

startIdx               int    - The starting index in input parameter 'targetStr'
                                from which the search for a number string will be
                                initiated. This useful in extracting multiple number
                                strings form a single 'targetStr'.

keepLeadingChars    string    - This string contains non-numeric characters which will be
                                retained as a prefix to the final number string extracted
                                from the 'targetStr' parameter. To be included, these characters
                                must exist in 'targetStr' and must immediately precede the
                                first instance of a number string.

                                For example, if the target string is "Hello $123789 world" and
                                parameter 'keepLeadingChars' includes the USA currency character,
                                '$', the returned number string would be '$123789'.  If no currency
                                character was included in 'keepLeadingChars', the returned number
                                string would be '123789'. It is worth noting that if the target
                                string was '$ 123789' and a currency symbol, '$', was included
                                in 'keepLeadingChars', the returned number string would still be
                                '123789' because 'keepLeadingChars' characters must immediately
                                precede the string of numeric digits in 'targetStr'.

                                Specifically, if the plus ('+') and minus ('-') sign are NOT
                                included in 'keepLeadingChars' those leading number signs will
                                never be included in the final number string.

                                Leading characters will not be repeated. If for some reason you
                                wanted to retain two leading currency symbols ("$$") it would be
                                necessary to include two currency characters in 'keepLeadingChars'.

keepInteriorChars   string    - This string contains non-numeric characters which will be retained
                                as valid characters within the final extracted number string. The
                                characters must exist withing the first instance of a number string
                                located in 'targetStr'. Such interior characters might include
                                thousands separators (commas) or decimal points (periods).

                                For example, if a comma and a period are included in 'keepInteriorChars'
                                and the target string is "Hello word 123,456,789.25 !", the returned
                                number string would be "123,456,789.25".  If the comma character was
                                NOT included in the 'keepInteriorChars' string, the returned number
                                string would be '123', since the number string extraction parser
                                would break on the comma, a non-numeric digit.

                                'keepInteriorChars' will NOT allow multiple non-numeric characters
                                to exist within the interior of the final extracted number string.
                                Only single non-numeric characters are allowed within a number string.

keepTrailingChars   string    - This string contains non-numeric characters which should be retained
                                at the end of the final number string. By default, a non-numeric
                                character will mark the end of a number string. However, if the caller
                                elects to use parameter 'keepTrailingChars' to retain non-numeric
                                characters such as a trailing right-parenthesis, then those non-numeric
                                characters will be retained in the final extracted number string.

                                Trailing characters will not be repeated. If for some reason you
                                wanted to retain two closing parentheses symbols ("))") it would be
                                necessary to include closing parentheses characters in 'keepTrailingChars'.

                                It should be emphasized that 'keepTrailingChars' must immediately
                                follow the first instance of a number string in parameter, 'targetStr'.

                                Example #1:
                                  Target String = "Hello world, (1234). Today is new day."
                                  keepLeadingChars = "("
                                  keepInteriorChars = ""
                                  keepTrailingChars= ")"
                                  Extracted Number String = "(1234)"

                                Example #2:
                                  Target String = "Hello world, USA GDP growth is projected at 1.8%."
                                  keepLeadingChars = ""
                                  keepInteriorChars = "."
                                  keepTrailingChars= "%"
                                  Extracted Number String = "1.8%"

------------------------------------------------------------------------

Return Values

NumStrProfileDto    - If successful, this method will return a type 'NumStrProfileDto'
                      populated with the extracted number string and additional profile
                      information related to the extracted number string.

   type NumStrProfileDto struct {

         TargetStr            string   //  The original target string which is scanned for a
                                       //    number string

         TargetStrStartIndex  int      //  The starting index in 'TargetStr' from which the
                                       //    number string search was initiated.

         LeadingSignIndex     int      //  The string index of a leading sign in 'NumStr' below. If a
                                       //    leading sign character is NOT present in 'NumStr' this
                                       //    value is set to -1

         LeadingSignChar      string   //  If a leading sign character (plus '+' or minus '-')
                                       //    exists in data field 'NumStr' (below), it is stored
                                       //    in this string.

         FirstNumCharIndex    int      //  The index in 'TargetStr' (above) where the first character
                                       //    of the extracted number string is located.

         NextTargetStrIndex   int      //  The index of the next character in 'TargetStr' immediately
                                       //    following the extracted number string.

         NumStrLen            int      //  The length of the extracted number string.

         NumStr               string   //  The number string extracted from 'TargetStr'.
   }

error               - If 'startIndex' is less than zero or if 'startIndex' exceeds the last character
                      index in 'targetStr', an error will be returned. If no errors are encountered,
                      this value is set to 'nil'.

func (StrOps) FindFirstNonSpaceChar

func (sops StrOps) FindFirstNonSpaceChar(targetStr string, startIndex, endIndex int) (int, error)

FindFirstNonSpaceChar - Returns the string index of the first non-space character in a string segment. The string to be searched is input parameter 'targetStr'. The string segment which will be searched from left to right in 'targetStr' is defined by the starting index ('startIndex') and the ending index ('endIndex').

Searching from left to right, this method identifies the first non-space character (any character that is NOT a space ' ') in the target string segment and returns the index associated with that non-space character.

------------------------------------------------------------------------

Return Values

This method returns the index of the first non-space character in the target string
segment using a left to right search. If the target string is an empty string or
consists of space characters, this method returns a value of -1.

func (StrOps) FindLastNonSpaceChar

func (sops StrOps) FindLastNonSpaceChar(targetStr string, startIdx, endIdx int) (int, error)

FindLastNonSpaceChar - Returns the string index of the last non-space character in a string segment. The string to be searched is input parameter, 'targetStr'. The string segment is further defined by input parameters 'startIdx' and 'endIdx'. These indexes define a segment within 'targetStr' which will be searched to identify the last non-space character.

The search is a backwards search, from right to left, conducted within the defined 'targetStr' segment. The search therefore starts at 'endIdx' and proceeds towards 'startIdx' until the last non-space character in the string segment is identified.

If the last non-space character is found, that string index is returned. If the string segment consists entirely of space characters, the return value is -1.

if 'targetStr' is a zero length string, an error will be triggered. Likewise, if 'startIdx' of 'endIdx' are invalid, an error will be returned.

func (StrOps) FindLastSpace

func (sops StrOps) FindLastSpace(targetStr string, startIdx, endIdx int) (int, error)

FindLastSpace - Returns a string index indicating the last space character (' ') in a string segment. The string segment is defined by input parameters, 'startIdx' and 'endIdx'.

The string segment search proceeds backwards, from right to left. The search therefore starts at 'endIdx' and proceeds towards 'startIdx' until the last space character in the string segment is identified.

If a valid index for the last space character is found in the string segment, that index value is returned. If a space character is NOT found in the specified string segment, a value of -1 is returned.

if 'targetStr' is a zero length string, an error will be triggered. Likewise, if 'startIdx' of 'endIdx' are invalid, an error will be returned.

func (StrOps) FindLastWord

func (sops StrOps) FindLastWord(
	targetStr string,
	startIndex,
	endIndex int) (beginWrdIdx,
	endWrdIdx int,
	isAllOneWord,
	isAllSpaces bool,
	err error)

FindLastWord - Returns the beginning and ending indexes of the last word in a target string segment. A 'word' is defined here as a contiguous set of non-space characters delimited by spaces or the beginning and ending indexes of the target string segment. Note, for purposes of this method, a 'word' my consist of a single non-space character such as an article 'a' or a punctuation mark '.'

------------------------------------------------------------------------

Examples

Example (1)
  In the text string segment:

  "The cow jumped over the moon."

  The last word would be defined as "moon."

  Example (2)
    In the text string segment:

    "  somewhere over the rainbow  "

    The last word would be defined as "rainbow"

------------------------------------------------------------------------

The string to be searched is contained in input parameter, 'targetStr'. The string segment within 'targetStr' is defined by input parameters 'startIndex' and 'endIndex'.

If the entire string segment is classified as a 'word', meaning that there are no space characters in the string segment, the returned values for 'beginWrdIdx' and 'endWrdIdx' will be equal to the input parameters 'startIndex' and 'endIndex'.

If the string segment is consists entirely of space characters, the returned 'beginWrdIdx' and 'endWrdIdx' will be set equal to -1 and the returned value, 'isAllSpaces' will be set to 'true'.

If 'targetStr' is an empty string, an error will be returned.

------------------------------------------------------------------------

Input Parameters

targetStr   string - The string containing the string segment which
                     will be searched to identify the last word
                     in the string segment.

startIndex     int - The index marking the beginning of the string
                     segment in 'targetStr'.

endIndex       int - The index marking the end of the string segment
                     in 'targetStr'.

------------------------------------------------------------------------

Return Values

beginWrdIdx    int  - The index marking the beginning of the last word
                      in the string segment identified by input parameters
                      'startIndex' and 'endIndex'. If the string segment
                      consists of all spaces or is empty, this value is
                      set to -1.

endWrdIdx      int  - The index marking the end of the last word in the
                      string segment identified by input parameters 'startIndex'
                      and 'endIndex'. If the string segment consists of all
                      spaces or is empty, this value is set to -1.

isAllOneWord   bool - If the string segment identified by input parameters
                      'startIndex' and 'endIndex' consists entirely of non-space
                      characters (characters other than ' '), this value is set
                      to 'true'.

isAllSpaces    bool - If the string segment identified by input parameters
                      'startIndex' and 'endIndex' consists entirely of space
                      characters (character = ' '), this value is set to 'true'.

err           error - If targetStr is empty or if startIndex or endIndex is invalid,
                      an error is returned. If the method completes successfully,
                      err = nil.

func (StrOps) FindRegExIndex

func (sops StrOps) FindRegExIndex(targetStr string, regex string) []int

FindRegExIndex - returns a two-element slice of integers defining the location of the leftmost match in targetStr of the regular expression (regex).

------------------------------------------------------------------------

Return Value

The return value is an array of integers. If no match is found the return
value is 'nil'.  If regular expression is successfully matched, the match
will be located at targetStr[loc[0]:loc[1]]. Again, a return value of 'nil'
signals that no match was found.

func (*StrOps) GetReader

func (sops *StrOps) GetReader() io.Reader

GetReader - Returns an io.Reader which will read the private member data element StrOps.stringData.

func (StrOps) GetSoftwareVersion

func (sops StrOps) GetSoftwareVersion() string

GetSoftwareVersion - Returns the software version for package 'strops'.

func (*StrOps) GetStringData

func (sops *StrOps) GetStringData() string

GetStringData - Returns the current value of internal member string, StrOps.stringData

func (StrOps) GetValidBytes

func (sops StrOps) GetValidBytes(targetBytes, validBytes []byte) ([]byte, error)

GetValidBytes - Receives an array of 'targetBytes' which will be examined to determine the validity of individual bytes or characters. Each character (byte) in input array 'targetBytes' will be compared to input parameter 'validBytes', another array of bytes. If a character in 'targetBytes' also exists in 'validBytes' it will be considered valid and included in the returned array of bytes.

------------------------------------------------------------------------

Input Parameters

targetBytes  [] byte  - An array of characters (bytes) which will be examined
                        for valid characters. The list of valid characters is
                        found in input parameter 'validBytes'. Valid characters
                        in targetBytes will be returned by this method as an
                        array of bytes. Invalid characters will be discarded.

validBytes  [] byte   - An array of bytes containing valid characters. If a character
                        (byte) in 'targetBytes' is also present in 'validBytes' it will
                        be classified as 'valid' and included in the returned array of
                        bytes. Invalid characters will be discarded.

------------------------------------------------------------------------

Return Values

[] byte  - An array of bytes which contains bytes that are present in both 'targetBytes'
           and 'validBytes'. Note: If all characters in 'targetBytes' are classified as
           'invalid', the returned array of bytes will be a zero length array.

error    - If the method completes successfully this value is 'nil'. If an error is
           encountered this value will contain the error message. Examples of possible
           errors include a zero length 'targetBytes array or 'validBytes' array.

func (StrOps) GetValidRunes

func (sops StrOps) GetValidRunes(targetRunes []rune, validRunes []rune) ([]rune, error)

GetValidRunes - Receives an array of 'targetRunes' which will be examined to determine the validity of individual runes or characters. Each character (rune) in input array 'targetRunes' will be compared to input parameter 'validRunes', another array of runes. If a character in 'targetRunes' also exists in 'validRunes', that character will be considered valid and included in the returned array of runes.

------------------------------------------------------------------------

Input Parameters

targetRunes    [] rune  - An array of characters (runes) which will be examined
                          for valid characters. The list of valid characters is
                          found in input parameter 'validRunes'. Valid characters
                          in targetRunes will be returned by this method as an
                          array of runes. Invalid characters will be discarded.

validRunes    [] rune  - An array of runes containing valid characters. If a character
                         (rune) in targetRunes is also present in 'validRunes' it will
                         be classified as 'valid' and included in the returned array of
                         runes. Invalid characters will be discarded.

------------------------------------------------------------------------

Return Values

[] rune  - An array of runes which contains runes that are present in 'targetRunes' and
           'validRunes'. Note: If all characters in 'targetRunes' are classified as
           'invalid', the returned array of runes will be a zero length array.

error    - If the method completes successfully this value is 'nil'. If an error is
           encountered this value will contain the error message. Examples of possible
           errors include a zero length 'targetRunes array or 'validRunes' array.

func (StrOps) GetValidString

func (sops StrOps) GetValidString(targetStr string, validRunes []rune) (string, error)

GetValidString - Validates the individual characters in input parameter string, 'targetStr'. To identify valid characters, the characters in 'targetStr' are compared against input parameter 'validRunes', an array of type rune. If a character exists in both 'targetStr' and 'validRunes' it is deemed valid and returned in an output string.

------------------------------------------------------------------------

Input Parameter

targetStr  string - The string which will be screened for valid characters.

validRunes []rune - An array of type rune containing valid characters. Characters
                    which exist in both 'targetStr' and 'validRunes' will be
                    returned as a new string. Invalid characters are discarded.

------------------------------------------------------------------------

Return Values

string - This string will be returned containing valid characters extracted
         from 'targetStr'. A character is considered valid if it exists in
         both 'targetStr' and 'validRunes'. Invalid characters are discarded.
         This means that if no valid characters are identified, a zero length
         string will be returned.

error  - If the method completes successfully this value is 'nil'. If an error is
         encountered this value will contain the error message. Examples of possible
         errors include a zero length 'targetStr' (string) or a zero length
         'validRunes' array.

func (StrOps) IsEmptyOrWhiteSpace

func (sops StrOps) IsEmptyOrWhiteSpace(targetStr string) bool

IsEmptyOrWhiteSpace - If a string is zero length or consists solely of white space (contiguous spaces), this method will return 'true'.

Otherwise, a value of false is returned.

func (StrOps) LowerCaseFirstLetter added in v2.0.1

func (sops StrOps) LowerCaseFirstLetter(str string) string

LowerCaseFirstLetter - Finds the first alphabetic character in a string (a-z A-Z) and converts it to lower case.

func (StrOps) MakeSingleCharString

func (sops StrOps) MakeSingleCharString(charRune rune, strLen int) (string, error)

MakeSingleCharString - Creates a string of length 'strLen' consisting of a single character passed through input parameter, 'charRune' as type 'rune'.

func (StrOps) NewPtr

func (sops StrOps) NewPtr() *StrOps

NewPtr - Returns a pointer to a new instance of StrOps. Useful for cases requiring io.Reader and io.Writer.

func (*StrOps) Read

func (sops *StrOps) Read(p []byte) (n int, err error)

Read - Implements io.Reader interface. Read reads up to len(p) bytes into 'p'. This method supports buffered 'read' operations.

The internal member string variable, 'StrOps.stringData' is written into 'p'. When the end of 'StrOps.stringData' is written to 'p', the method returns error = 'io.EOF'.

'StrOps.stringData' can be accessed through Getter an Setter methods, GetStringData() and SetStringData()

func (StrOps) ReadStringFromBytes added in v2.0.1

func (sops StrOps) ReadStringFromBytes(
	bytes []byte,
	startIdx int) (extractedStr string, nextStartIdx int)

ReadStringFromBytes - Receives a byte array and retrieves a string. The beginning of the string is designated by input parameter 'startIdx'. The end of the string is determined when a carriage return ('\r'), vertical tab ('\v') or a new line character ('\n') is encountered.

The parsed string is returned to the caller along with 'nextStartIdx', which is the byte array index of the beginning of the next string.

------------------------------------------------------------------------

Input Parameters

bytes          []byte - An array of bytes from which a string will be extracted
                        and returned.

startIdx          int - The starting index in input parameter 'bytes' where the string
                        extraction will begin. The string extraction will cease when
                        a carriage return ('\r'), a vertical tab ('\v') or a new line
                        character ('\n') is encountered.

------------------------------------------------------------------------

Return Values

extractedStr   string - The string extracted from input parameter 'bytes' beginning
                        at the index in 'bytes' indicated by input parameter 'startIdx'.

nextStartIdx      int - The index of the beginning of the next string in the byte array
                        'bytes' after 'extractedString'. If no more strings exist in the
                        the byte array, 'nextStartIdx' will be set to -1.

func (StrOps) ReplaceBytes

func (sops StrOps) ReplaceBytes(targetBytes []byte, replacementBytes [][]byte) ([]byte, error)

ReplaceBytes - Replaces characters in a target array of bytes ([]bytes) with those specified in a two dimensional slice of bytes.

------------------------------------------------------------------------

Input Parameters

targetBytes  []byte       - The byte array which will be examined. If characters ('bytes') eligible
                            for replacement are identified by replacementBytes[i][0] they will be
                            replaced by the character specified in replacementBytes[i][1].

replacementBytes [][]byte - A two dimensional slice of type byte. Element [i][0] contains the
                            target character to locate in 'targetBytes'. Element[i][1] contains
                            the replacement character which will replace the target character
                            in 'targetBytes'. If the replacement character element [i][1] is
                            a zero value, the target character will not be replaced. Instead,
                            it will be eliminated or removed from the returned byte array ([]byte).

------------------------------------------------------------------------

Return Values

[]byte  - The returned byte array containing the characters and replaced characters
          from the original 'targetBytes' array.

error  - If the method completes successfully this value is 'nil'. If an error is
         encountered this value will contain the error message. Examples of possible
         errors include a zero length targetBytes[] array or replacementBytes[][] array.
         In addition, if any of the replacementBytes[][x] 2nd dimension elements have
         a length less than two, an error will be returned.

func (StrOps) ReplaceMultipleStrs

func (sops StrOps) ReplaceMultipleStrs(targetStr string, replaceArray [][]string) (string, error)

ReplaceMultipleStrs - Replaces all instances of string replaceArray[i][0] with replacement string from replaceArray[i][1] in 'targetStr'.

Note: The original 'targetStr' is NOT altered.

Input parameter 'replaceArray' should be passed as a two-dimensional slice. If the length of the 'replaceArray' second dimension is less than '2', an error will be returned.

func (StrOps) ReplaceNewLines

func (sops StrOps) ReplaceNewLines(targetStr string, replacement string) string

ReplaceNewLines - Replaces New Line characters from string. If the specified replacement string is empty, the New Line characters are simply removed from the input parameter, 'targetStr'.

func (StrOps) ReplaceRunes

func (sops StrOps) ReplaceRunes(targetRunes []rune, replacementRunes [][]rune) ([]rune, error)

ReplaceRunes - Replaces characters in a target array of runes ([]rune) with those specified in a two-dimensional slice of runes, 'replacementRunes[][]'.

------------------------------------------------------------------------

Input Parameters

targetRunes        []rune - The rune array which will be examined. If target characters ('runes')
                            eligible for replacement are identified by replacementRunes[i][0],
                            they will be replaced by the character specified in
                            replacementRunes[i][1].

replacementRunes [][]rune - A two dimensional slice of type 'rune'. Element [i][0] contains the
                            target character to locate in 'targetRunes'. Element[i][1] contains
                            the replacement character which will replace the target character in
                            'targetRunes'. If the replacement character element [i][1] is a zero
                            value, the  target character will not be replaced. Instead, it will
                            be eliminated or removed from the returned rune array ([]rune).

------------------------------------------------------------------------

Return Values

[]rune  - The returned rune array containing the characters and replaced characters
          from the original 'targetRunes' array.

error   - If the method completes successfully this value is 'nil'. If an error is
          encountered this value will contain the error message. Examples of possible
          errors include a zero length 'targetRunes' array or 'replacementRunes' array.
          In addition, if any of the replacementRunes[][x] 2nd dimension elements have
          a length less than two, an error will be returned.

func (StrOps) ReplaceStringChars

func (sops StrOps) ReplaceStringChars(
	targetStr string,
	replacementRunes [][]rune) (string, error)

ReplaceStringChars - Replaces string characters in a target string ('targetStr') with those specified in a two dimensional slice of runes, 'replacementRunes[][]'.

------------------------------------------------------------------------

Input Parameters

targetStr          string  - The string which will be examined. If target string characters
                             eligible for replacement are identified by replacementRunes[i][0],
                             they will be replaced by the character specified in
                             replacementRunes[i][1].

replacementRunes [][]rune  - A two dimensional slice of type 'rune'. Element [i][0] contains
                             the target character to locate in 'targetStr'. Element[i][1]
                             contains the replacement character which will replace the target
                             character in 'targetStr'. If the replacement character
                             element [i][1] is a zero value, the target character will not
                             be replaced. Instead, it will be eliminated or removed from the
                             returned string.

------------------------------------------------------------------------

Return Values

string  - The returned string containing the characters and replaced characters
          from the original target string, ('targetStr').

error   - If the method completes successfully this value is 'nil'. If an error is
          encountered this value will contain the error message. Examples of possible
          errors include a zero length 'targetStr' or 'replacementRunes[][]' array.
          In addition, if any of the replacementRunes[][x] 2nd dimension elements have
          a length less than two, an error will be returned.

func (*StrOps) SetStringData

func (sops *StrOps) SetStringData(str string)

SetStringData - Sets the value of internal string data element, StrOps.stringData. It also zeros internal fields sops.cntBytesWritten and sops.cntBytesRead.

func (StrOps) StrCenterInStr

func (sops StrOps) StrCenterInStr(strToCenter string, fieldLen int) (string, error)

StrCenterInStr - returns a string which includes a left pad blank string plus the original string ('strToCenter'), plus a right pad blank string.

The returned string will effectively center the original string ('strToCenter') in a field of specified length ('fieldLen').

func (StrOps) StrCenterInStrLeft

func (sops StrOps) StrCenterInStrLeft(strToCenter string, fieldLen int) (string, error)

StrCenterInStrLeft - returns a string which includes a left pad blank string plus the original string. It does NOT include the Right pad blank string.

Nevertheless, the complete string will effectively center the original string in a field of specified length.

Example:

In this example the total field length is 15. The length of the test string,
"Hello", is 5. In order to center the test string in a field with length of 15,
there will be 5-spaces on the left and 5-spaces on the right. This method will
compute the left-pad spaces necessary to center the string in a field with length
of 15, but will only include the padded left margin of 5-spaces. It will NOT
include the trailing 5-spaces on the right.

In the following example, the final result string will substitute the'@' character
for the white space character (0x20) in order to illustrate the padding added by
this method.

 strToCenter     = "Hello"
 fieldLen        = 15
 Returned String = "@@@@@Hello" or "     Hello"

func (StrOps) StrGetCharCnt

func (sops StrOps) StrGetCharCnt(targetStr string) int

StrGetCharCnt - Uses the 'len' method to return the number of rune characters in a string.

func (StrOps) StrGetRuneCnt

func (sops StrOps) StrGetRuneCnt(targetStr string) int

StrGetRuneCnt - Uses utf8 Rune Count function to return the number of characters in a string.

func (StrOps) StrLeftJustify

func (sops StrOps) StrLeftJustify(strToJustify string, fieldLen int) (string, error)

StrLeftJustify - Creates a new string with a total length equal to input parameter 'fieldLen'.

Input parameter 'strToJustify' is placed on the left side of the output string and spaces are padded to the right in order to create a string with total length of 'fieldLen'.

Example:

fieldLen = 15
strToJustify    = "Hello World"
Returned String = "Hello World    "
String Index    =  012345648901234

func (StrOps) StrPadLeftToCenter

func (sops StrOps) StrPadLeftToCenter(strToCenter string, fieldLen int) (string, error)

StrPadLeftToCenter - Returns a blank string which allows centering of the target string in a fixed length field.

Example:

Assume that total field length ('fieldlen') is 70. Assume that the string to Center ('strToCenter') is 10-characters. In order to center a 10-character string in a 70-character field, 30-space characters would need to be positioned on each side of the string to center. This method only returns the left margin, or a string consisting of 30-spaces.

func (StrOps) StrRightJustify

func (sops StrOps) StrRightJustify(strToJustify string, fieldLen int) (string, error)

StrRightJustify - Returns a string where input parameter 'strToJustify' is right justified. The length of the returned string is determined by input parameter 'fieldlen'.

Example:

If the total field length ('fieldLen') is specified as 50-characters and the
length of string to justify ('strToJustify') is 20-characters, then this method
would return a string consisting of 30-space characters plus the 'strToJustify'.

func (StrOps) StripBadChars added in v2.0.3

func (sops StrOps) StripBadChars(
	targetStr string,
	badChars []string) (cleanStr string, strLen int)

StripBadChars - Removes/deletes specified characters from a string. The characters to remove are contained in a string array passed as input parameter, 'badChars'.

All instances of a 'badChars' character are deleted from the target string. The target string is passed through input parameter, 'targetStr'.

func (StrOps) StripLeadingChars added in v2.0.3

func (sops StrOps) StripLeadingChars(
	targetStr string,
	badChars []string) (cleanStr string, strLen int)

StripLeadingChars - Strips or deletes characters specified by input parameter 'badChars' from the front of 'targetStr'.

The method then returns a string which does not contain leading 'bad characters'. In addition, the length of the 'clean string' is also returned.

func (StrOps) StripTrailingChars added in v2.0.3

func (sops StrOps) StripTrailingChars(
	targetStr string,
	badChars []string) (cleanStr string, strLen int)

StripTrailingChars - Strips or deletes bad characters from the end of input parameter 'targetStr'. Bad characters are identified by the input parameter, 'badChars'.

The method then returns the cleaned string and the length of the cleaned string to the caller. The cleaned string is equivalent to input parameter 'targetStr' minus the trailing bad characters at the end of 'targetStr'.

func (StrOps) SwapRune

func (sops StrOps) SwapRune(targetStr string, oldRune rune, newRune rune) (string, error)

SwapRune - Swaps all instances of 'oldRune' character with 'newRune' character in input parameter target string ('targetStr').

func (StrOps) TrimMultipleChars

func (sops StrOps) TrimMultipleChars(
	targetStr string,
	trimChar rune) (rStr string, err error)

TrimMultipleChars - Performs the following operations on strings:

  1. Trims Right and Left ends of 'targetStr' for all instances of 'trimChar'
  2. Within the interior of a string, multiple instances of 'trimChar' are reduced to a single instance.

Example:

targetStr = "       Hello          World        "
trimChar  = ' ' (One Space)
returned string (rStr) = "Hello World"

func (StrOps) TrimStringEnds

func (sops StrOps) TrimStringEnds(
	targetStr string,
	trimChar rune) (rStr string, err error)

TrimStringEnds - Removes all instances of input parameter 'trimChar' from the beginning and end of input parameter string 'targetStr'.

func (StrOps) UpperCaseFirstLetter added in v2.0.1

func (sops StrOps) UpperCaseFirstLetter(str string) string

UpperCaseFirstLetter - Finds the first alphabetic character in a string (a-z A-Z) and converts it to upper case.

func (*StrOps) Write

func (sops *StrOps) Write(p []byte) (n int, err error)

Write - Implements the io.Writer interface. Write writes len(p) bytes from p to the underlying data stream. In this case the underlying data stream is private member variable string, 'StrOps.stringData'.

Receives a byte array 'p' and writes the contents to a string, private structure data element 'StrOps.stringData'.

'StrOps.stringData' can be accessed through 'Getter' and 'Setter' methods, 'GetStringData()' and 'SetStringData()'.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL