github.com/blend/go-sdk@v1.20220411.3/stringutil/has_prefix_caseless.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  // HasPrefixCaseless returns if a corpus has a prefix regardless of casing.
    11  func HasPrefixCaseless(corpus, prefix string) bool {
    12  	corpusLen := len(corpus)
    13  	prefixLen := len(prefix)
    14  
    15  	if corpusLen < prefixLen {
    16  		return false
    17  	}
    18  
    19  	for x := 0; x < prefixLen; x++ {
    20  		charCorpus := uint(corpus[x])
    21  		charPrefix := uint(prefix[x])
    22  
    23  		if charCorpus-LowerA <= LowerDiff {
    24  			charCorpus = charCorpus - 0x20
    25  		}
    26  
    27  		if charPrefix-LowerA <= LowerDiff {
    28  			charPrefix = charPrefix - 0x20
    29  		}
    30  		if charCorpus != charPrefix {
    31  			return false
    32  		}
    33  	}
    34  	return true
    35  }