-
Notifications
You must be signed in to change notification settings - Fork 1
/
trim_space.go
32 lines (26 loc) · 890 Bytes
/
trim_space.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2023-2024 Onur Cinar.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://github.com/cinar/checker
package v2
import (
"reflect"
"strings"
)
const (
// nameTrimSpace is the name of the trim normalizer.
nameTrimSpace = "trim"
)
// TrimSpace returns the value of the string with whitespace removed from both ends.
func TrimSpace(value string) (string, error) {
return strings.TrimSpace(value), nil
}
// reflectTrimSpace returns the value of the string with whitespace removed from both ends.
func reflectTrimSpace(value reflect.Value) (reflect.Value, error) {
newValue, err := TrimSpace(value.Interface().(string))
return reflect.ValueOf(newValue), err
}
// makeTrimSpace returns the trim space normalizer function.
func makeTrimSpace(_ string) CheckFunc[reflect.Value] {
return reflectTrimSpace
}