gitlab.com/evatix-go/core@v1.3.55/converters/StringsToMapConverter.go (about)

     1  package converters
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/internal/strutilinternal"
     5  )
     6  
     7  type StringsToMapConverter []string
     8  
     9  func (it StringsToMapConverter) SafeStrings() []string {
    10  	if it.IsEmpty() {
    11  		return []string{}
    12  	}
    13  
    14  	return it
    15  }
    16  
    17  func (it StringsToMapConverter) Strings() []string {
    18  	return it
    19  }
    20  
    21  func (it *StringsToMapConverter) Length() int {
    22  	if it == nil || *it == nil {
    23  		return 0
    24  	}
    25  
    26  	return len(*it)
    27  }
    28  
    29  func (it *StringsToMapConverter) IsEmpty() bool {
    30  	return it.Length() == 0
    31  }
    32  
    33  func (it *StringsToMapConverter) HasAnyItem() bool {
    34  	return it.Length() > 0
    35  }
    36  
    37  func (it *StringsToMapConverter) LastIndex() int {
    38  	return it.Length() - 1
    39  }
    40  
    41  func (it StringsToMapConverter) LineSplitMapOptions(
    42  	isTrim bool,
    43  	splitter string,
    44  ) map[string]string {
    45  	if isTrim {
    46  		return it.LineSplitMapTrim(splitter)
    47  	}
    48  
    49  	return it.LineSplitMap(splitter)
    50  }
    51  
    52  func (it StringsToMapConverter) LineProcessorMapOptions(
    53  	isTrimBefore bool,
    54  	processorFunc func(line string) (key, val string),
    55  ) map[string]string {
    56  	return strutilinternal.
    57  		SliceToMapConverter(it.Strings()).
    58  		LineProcessorMapOptions(
    59  			isTrimBefore,
    60  			processorFunc)
    61  }
    62  
    63  func (it StringsToMapConverter) LineProcessorMapStringIntegerTrim(
    64  	processorFunc func(line string) (key string, val int),
    65  ) map[string]int {
    66  	return it.LineProcessorMapStringIntegerOptions(
    67  		true,
    68  		processorFunc)
    69  }
    70  
    71  func (it StringsToMapConverter) LineProcessorMapStringIntegerOptions(
    72  	isTrimBefore bool,
    73  	processorFunc func(line string) (key string, val int),
    74  ) map[string]int {
    75  	return strutilinternal.
    76  		SliceToMapConverter(it.Strings()).
    77  		LineProcessorMapStringIntegerOptions(
    78  			isTrimBefore,
    79  			processorFunc)
    80  }
    81  
    82  func (it StringsToMapConverter) LineProcessorMapStringAnyTrim(
    83  	processorFunc func(line string) (key string, val interface{}),
    84  ) map[string]interface{} {
    85  	return it.LineProcessorMapStringAnyOptions(
    86  		true,
    87  		processorFunc)
    88  }
    89  
    90  func (it StringsToMapConverter) LineProcessorMapStringAnyOptions(
    91  	isTrimBefore bool,
    92  	processorFunc func(line string) (key string, val interface{}),
    93  ) map[string]interface{} {
    94  	return strutilinternal.
    95  		SliceToMapConverter(it.Strings()).
    96  		LineProcessorMapStringAnyOptions(
    97  			isTrimBefore,
    98  			processorFunc)
    99  }
   100  
   101  func (it StringsToMapConverter) LineSplitMapTrim(
   102  	splitter string,
   103  ) map[string]string {
   104  	return strutilinternal.
   105  		SliceToMapConverter(it.Strings()).
   106  		LineSplitMapTrim(
   107  			splitter,
   108  		)
   109  }
   110  
   111  func (it StringsToMapConverter) LineSplitMap(
   112  	splitter string,
   113  ) map[string]string {
   114  	return strutilinternal.
   115  		SliceToMapConverter(it.Strings()).
   116  		LineSplitMap(
   117  			splitter,
   118  		)
   119  }