Documentation
¶
Overview ¶
Package strutil 문자열 처리를 위한 다양한 유틸리티 함수들을 제공합니다.
Index ¶
- func AnyContent(strs ...string) bool
- func Comma[T Integer](num T) string
- func Mask(data string) string
- func NormalizeMultiline(s string) string
- func NormalizeSpace(s string) string
- func SplitClean(s, sep string) []string
- func StripHTML(s string) string
- func Truncate(s string, limit int) string
- type Integer
- type KeywordMatcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyContent ¶ added in v1.1.0
AnyContent 주어진 문자열 목록 중 하나라도 비어있지 않은(공백 제외) 값이 존재하는지 검사합니다.
func Comma ¶ added in v1.1.0
Comma 정수를 천 단위 구분 기호(,)가 포함된 문자열로 변환합니다. (예: 1234567 -> "1,234,567")
Example ¶
fmt.Println(Comma(1234567)) fmt.Println(Comma(100))
Output: 1,234,567 100
func NormalizeMultiline ¶ added in v1.1.0
NormalizeMultiline 각 줄의 공백을 정규화하고, 연속된 빈 줄을 하나로 축약하여 전체 텍스트를 정리합니다.
func NormalizeSpace ¶ added in v1.1.0
NormalizeSpace 문자열의 앞뒤 공백을 제거하고, 내부의 연속된 공백을 단일 공백(' ')으로 정규화합니다.
Example ¶
fmt.Println(NormalizeSpace(" Hello World "))
Output: Hello World
func SplitClean ¶ added in v1.1.0
SplitClean 주어진 구분자로 문자열을 분리한 후, 각 항목의 앞뒤 공백을 제거하고 빈 문자열을 제외(Filter)한 슬라이스를 반환합니다. 입력 문자열이 비어있거나 유효한 항목이 없는 경우 nil을 반환합니다. 예: "apple, , banana, " (구분자 ",") -> ["apple", "banana"]
func StripHTML ¶ added in v1.1.0
StripHTML 문자열에서 HTML 태그와 주석을 제거하고, HTML 엔티티를 디코딩하여 순수한 텍스트만 추출합니다.
Example ¶
htmlStr := "<b>Bold</b> & <i>Italic</i>" fmt.Println(StripHTML(htmlStr))
Output: Bold & Italic
Types ¶
type Integer ¶
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Integer 모든 정수 타입을 포괄하는 제네릭 인터페이스
type KeywordMatcher ¶ added in v1.1.0
type KeywordMatcher struct {
// contains filtered or unexported fields
}
KeywordMatcher 키워드 매칭을 수행하는 상태 기반(Stateful) 구조체입니다.
생성 시점에 키워드 파싱과 전처리(소문자 변환)를 수행합니다. 따라서 동일한 키워드 셋으로 여러 문자열을 검사해야 하는 대량 처리 상황에서 반복적인 파싱과 메모리 할당 비용을 제거하여 높은 성능을 제공합니다.
Example ¶
ExampleKeywordMatcher KeywordMatcher의 사용 예시를 보여줍니다.
// 필터 조건: "go"를 포함하고, ("web" 또는 "http")를 포함해야 하며, "legacy"나 "v1"은 제외.
included := []string{"go", "web|http"}
excluded := []string{"legacy", "v1"}
matcher := NewKeywordMatcher(included, excluded)
candidates := []string{
"Modern Go Web Framework",
"Legacy Go HTTP Server (v1)",
"Python Web Server",
"Experimental Go HTTP Library",
}
for _, c := range candidates {
if matcher.Match(c) {
fmt.Println("Matched:", c)
}
}
Output: Matched: Modern Go Web Framework Matched: Experimental Go HTTP Library
func NewKeywordMatcher ¶ added in v1.1.0
func NewKeywordMatcher(included, excluded []string) *KeywordMatcher
NewKeywordMatcher 주어진 포함/제외 키워드로 새로운 KeywordMatcher를 생성합니다.
초기화 과정에서 다음 작업이 수행됩니다: 1. 모든 키워드를 소문자로 변환 (Case-Insensitive 매칭 준비) 2. 포함 키워드 내의 파이프(|) 구문을 파싱하여 그룹화 3. 빈 키워드 필터링
func (*KeywordMatcher) Match ¶ added in v1.1.0
func (m *KeywordMatcher) Match(s string) bool
Match 대상 문자열이 키워드 조건을 만족하는지 검사합니다.
문자열 s가 제외 키워드를 포함하지 않고, 모든 포함 키워드 그룹 조건을 만족하면 true를 반환합니다.