-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh.go
52 lines (49 loc) · 1.77 KB
/
h.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pgc
import "strings"
// isEmpty checks if the provided string is empty or consists solely of whitespace characters.
//
// The function trims leading and trailing whitespace from the input string `s` using
// strings.TrimSpace. It then evaluates the length of the trimmed string. If the length is
// zero, it indicates that the original string was either empty or contained only whitespace,
// and the function returns true. Otherwise, it returns false.
//
// Parameters:
// - `s`: A string that needs to be checked for emptiness.
//
// Returns:
//
// A boolean value:
// - true if the string is empty or contains only whitespace characters;
// - false if the string contains any non-whitespace characters.
//
// Example:
//
// result := isEmpty(" ") // result will be true
// result = isEmpty("Hello") // result will be false
func isEmpty(s string) bool {
trimmed := strings.TrimSpace(s)
return len(trimmed) == 0
}
// isNotEmpty checks if the provided string is not empty or does not consist solely of whitespace characters.
//
// This function leverages the IsEmpty function to determine whether the input string `s`
// is empty or contains only whitespace. It returns the negation of the result from IsEmpty.
// If IsEmpty returns true (indicating the string is empty or whitespace), isNotEmpty will return false,
// and vice versa.
//
// Parameters:
// - `s`: A string that needs to be checked for non-emptiness.
//
// Returns:
//
// A boolean value:
// - true if the string contains at least one non-whitespace character;
// - false if the string is empty or contains only whitespace characters.
//
// Example:
//
// result := isNotEmpty("Hello") // result will be true
// result = isNotEmpty(" ") // result will be false
func isNotEmpty(s string) bool {
return !isEmpty(s)
}