gitlab.com/evatix-go/core@v1.3.55/regexnew/newLazyRegexCreator.go (about)

     1  package regexnew
     2  
     3  type newLazyRegexCreator struct{}
     4  
     5  // New
     6  //
     7  //  used to create as vars
     8  func (it newLazyRegexCreator) New(
     9  	pattern string,
    10  ) *LazyRegex {
    11  	lazyRegex, _ := lazyRegexOnceMap.CreateOrExisting(
    12  		pattern)
    13  
    14  	return lazyRegex
    15  }
    16  
    17  // NewLock
    18  //
    19  //  used to generate inside method
    20  func (it newLazyRegexCreator) NewLock(
    21  	pattern string,
    22  ) *LazyRegex {
    23  	lazyRegex, _ := lazyRegexOnceMap.CreateOrExistingLock(
    24  		pattern)
    25  
    26  	return lazyRegex
    27  }
    28  
    29  func (it newLazyRegexCreator) TwoLock(
    30  	pattern, secondPattern string,
    31  ) (first, second *LazyRegex) {
    32  	lazyRegexLock.Lock()
    33  	defer lazyRegexLock.Unlock()
    34  
    35  	first = it.New(pattern)
    36  	second = it.New(secondPattern)
    37  
    38  	return first, second
    39  }
    40  
    41  func (it newLazyRegexCreator) ManyUsingLock(
    42  	patterns ...string,
    43  ) (patternsKeyAsMap map[string]*LazyRegex) {
    44  	if len(patterns) == 0 {
    45  		return map[string]*LazyRegex{}
    46  	}
    47  
    48  	lazyRegexLock.Lock()
    49  	defer lazyRegexLock.Unlock()
    50  
    51  	patternsKeyAsMap = make(
    52  		map[string]*LazyRegex,
    53  		len(patterns))
    54  
    55  	for _, pattern := range patterns {
    56  		patternsKeyAsMap[pattern] = it.New(pattern)
    57  	}
    58  
    59  	return patternsKeyAsMap
    60  }
    61  
    62  func (it newLazyRegexCreator) AllPatternsMap() map[string]*LazyRegex {
    63  	lazyRegexLock.Lock()
    64  	defer lazyRegexLock.Unlock()
    65  
    66  	return lazyRegexOnceMap.items
    67  }
    68  
    69  // NewLockIf
    70  //
    71  //  used to generate inside method
    72  //  lock must be performed when called from method.
    73  func (it newLazyRegexCreator) NewLockIf(
    74  	isLock bool,
    75  	pattern string,
    76  ) *LazyRegex {
    77  	if isLock {
    78  		return it.NewLock(pattern)
    79  	}
    80  
    81  	return it.New(pattern)
    82  }