github.com/blend/go-sdk@v1.20220411.3/stringutil/trim_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 // TrimPrefixCaseless trims a prefix from a corpus ignoring case. 11 func TrimPrefixCaseless(corpus, prefix string) string { 12 corpusLen := len(corpus) 13 prefixLen := len(prefix) 14 15 if corpusLen < prefixLen { 16 return corpus 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 corpus 32 } 33 } 34 35 return corpus[prefixLen:] 36 }