-
Notifications
You must be signed in to change notification settings - Fork 0
/
trim.go
33 lines (27 loc) · 832 Bytes
/
trim.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
33
// Package checker is a Go library for validating user input through struct tags.
//
// https://github.com/cinar/checker
//
// Copyright 2023 Onur Cinar. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//
package checker
import (
"reflect"
"strings"
)
// NormalizerTrim is the name of the normalizer.
const NormalizerTrim = "trim"
// makeTrim makes a normalizer function for the trim normalizer.
func makeTrim(_ string) CheckFunc {
return normalizeTrim
}
// normalizeTrim removes the whitespaces at the beginning and at the end of the given value.
func normalizeTrim(value, _ reflect.Value) Result {
if value.Kind() != reflect.String {
panic("string expected")
}
value.SetString(strings.Trim(value.String(), " \t"))
return ResultValid
}