gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/LeftMiddleRight.go (about)

     1  package corestr
     2  
     3  import (
     4  	"strings"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  	"gitlab.com/evatix-go/core/internal/strutilinternal"
     8  )
     9  
    10  type LeftMiddleRight struct {
    11  	LeftRight
    12  	Middle string
    13  }
    14  
    15  func InvalidLeftMiddleRightNoMessage() *LeftMiddleRight {
    16  	return &LeftMiddleRight{
    17  		LeftRight: LeftRight{
    18  			Left:    constants.EmptyString,
    19  			Right:   constants.EmptyString,
    20  			IsValid: false,
    21  			Message: constants.EmptyString,
    22  		},
    23  		Middle: constants.EmptyString,
    24  	}
    25  }
    26  
    27  func InvalidLeftMiddleRight(message string) *LeftMiddleRight {
    28  	return &LeftMiddleRight{
    29  		LeftRight: LeftRight{
    30  			Left:    constants.EmptyString,
    31  			Right:   constants.EmptyString,
    32  			IsValid: false,
    33  			Message: message,
    34  		},
    35  		Middle: constants.EmptyString,
    36  	}
    37  }
    38  
    39  func (it *LeftMiddleRight) MiddleTrim() string {
    40  	return strings.TrimSpace(it.Middle)
    41  }
    42  
    43  func (it *LeftMiddleRight) MiddleBytes() []byte {
    44  	return []byte(it.Middle)
    45  }
    46  
    47  func (it *LeftMiddleRight) IsMiddleEmpty() bool {
    48  	return it.Middle == ""
    49  }
    50  
    51  func (it *LeftMiddleRight) IsMiddleWhitespace() bool {
    52  	return strutilinternal.IsEmptyOrWhitespace(it.Middle)
    53  }
    54  
    55  func (it *LeftMiddleRight) HasValidNonEmptyMiddle() bool {
    56  	return it.IsValid && !it.IsMiddleEmpty()
    57  }
    58  
    59  func (it *LeftMiddleRight) HasValidNonWhitespaceMiddle() bool {
    60  	return it.IsValid && !it.IsMiddleWhitespace()
    61  }
    62  
    63  // HasSafeNonEmpty receiver.IsValid &&
    64  //		!receiver.IsLeftEmpty() &&
    65  //		!receiver.IsMiddleEmpty() &&
    66  //		!receiver.IsRightEmpty()
    67  func (it *LeftMiddleRight) HasSafeNonEmpty() bool {
    68  	return it.IsValid &&
    69  		!it.IsLeftEmpty() &&
    70  		!it.IsMiddleEmpty() &&
    71  		!it.IsRightEmpty()
    72  }
    73  
    74  func (it *LeftMiddleRight) IsAll(left, mid, right string) bool {
    75  	return it.Left == left &&
    76  		it.Right == right &&
    77  		it.Middle == mid
    78  }
    79  
    80  func (it *LeftMiddleRight) Clone() *LeftMiddleRight {
    81  	return &LeftMiddleRight{
    82  		LeftRight: *it.LeftRight.Clone(),
    83  		Middle:    it.Middle,
    84  	}
    85  }
    86  
    87  func (it *LeftMiddleRight) Clear() {
    88  	if it == nil {
    89  		return
    90  	}
    91  
    92  	it.LeftRight.Clear()
    93  	it.Middle = ""
    94  }
    95  
    96  func (it *LeftMiddleRight) Dispose() {
    97  	if it == nil {
    98  		return
    99  	}
   100  
   101  	it.Clear()
   102  }