Skip to content

Commit 19ec725

Browse files
committed
moji.Squeeze() always return nil (replace the original string directly) #72
1 parent d8a9de3 commit 19ec725

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

address/find.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func Find(argv1 string) [3]string {
256256
for {
257257
// Remove redundant spaces from the display name when the value is not a "quoted-string"
258258
if strings.HasPrefix(readbuffer[1], `"`) && strings.HasSuffix(readbuffer[1], `"`) { break }
259-
readbuffer[1] = moji.Squeeze(readbuffer[1], ' ')
259+
moji.Squeeze(&readbuffer[1], ' ')
260260
break
261261
}
262262
if rfc5322.IsQuotedAddress(readbuffer[1]) == false {

fact/09-lhost-code_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ func EngineTest(t *testing.T, enginename string, isexpected [][]IsExpected, publ
131131
// Read and decode each email file as a string
132132
cx++; if emailthing.Size == 0 { t.Errorf("%s %s is empty", ee, ef); continue }
133133

134-
mesg = moji.ToLF(mesg)
135-
fact, nyaan := Rise(mesg, emailthing.Path, ArgForRise)
134+
moji.ToLF(mesg); fact, nyaan := Rise(mesg, emailthing.Path, ArgForRise)
136135
cx++; if nyaan != nil { t.Logf("%s %s", ee, nyaan[0].Error()) }
137136
if len(fact) != 0 { sisi = append(sisi, fact...) }
138137
}

lhost/order.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func OrderBySubject(title string) []string {
6868
// The following order is decided by the first 2 words of Subject: header
6969
for _, e := range []string{"[", "]", "_"} { title = strings.Replace(title, e, " ", -1) }
7070

71-
if strings.Contains(title, " ") { title = moji.Squeeze(title, ' ') }
71+
if strings.Contains(title, " ") { moji.Squeeze(&title, ' ') }
7272
words := strings.SplitN(strings.ToLower(title), " ", 3)
7373
first := ""
7474

lhost/via-exim.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func init() {
410410
} else if len(e.Diagnosis) < len(anotherone[j]) {
411411
// Override the value of diagnostic code message with the value of alterrors
412412
// because the latter includes the former.
413-
anotherone[j] = moji.Squeeze(anotherone[j], ' ')
413+
moji.Squeeze(&anotherone[j], ' ')
414414
if strings.Contains(strings.ToLower(anotherone[j]), strings.ToLower(e.Diagnosis)) {
415415
// anotherone[j] contains the same error message stored in e.Diagnosis
416416
e.Diagnosis = anotherone[j]

moji/03-squeeze_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func TestSqueeze(t *testing.T) {
2222
{"", '?', ""},
2323
}
2424
for _, e := range ae {
25-
cx++; if Squeeze(e.text, e.char) != e.expected { t.Errorf("%s(%s, %c) returns %s", fn, e.text, e.char, e.expected) }
25+
cv := e.text
26+
cx++; if Squeeze(&cv, e.char); cv != e.expected { t.Errorf("%s(%s, %c) returns %s", fn, e.text, e.char, e.expected) }
2627
}
2728
t.Logf("The number of tests = %d", cx)
2829
}

moji/lib.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func Token(argv1 string, argv2 string, epoch int) string {
3333

3434
// Squeeze remove redundant characters from the given string
3535
// Arguments:
36-
// - argv0 (string): String including redundant characters like "neko chan"
37-
// - argv1 (string): Characters to be squeezed, for example " "
36+
// - argv0 (*string): String including redundant characters like "neko chan"
37+
// - argv1 (byte): Characters to be squeezed, for example ' '
3838
// Returns:
39-
// - (string): Squeezed string such as "neko chan"
40-
func Squeeze(argv0 string, argv1 byte) string {
41-
if argv0 == "" { return "" }
39+
// - (error): Always nil
40+
func Squeeze(argv0 *string, argv1 byte) error {
41+
if argv0 == nil || *argv0 == "" || strings.IndexByte(*argv0, argv1) < 0 { return nil }
4242

43-
bytebuffer := []byte(argv0)
43+
bytebuffer := []byte(*argv0)
4444
textbuffer := make([]byte, 0, len(bytebuffer))
4545

4646
cb := byte(0); for _, by := range bytebuffer {
@@ -49,7 +49,7 @@ func Squeeze(argv0 string, argv1 byte) string {
4949
textbuffer = append(textbuffer, by)
5050
cb = by
5151
}
52-
return string(textbuffer)
52+
*argv0 = string(textbuffer); return nil
5353
}
5454

5555
// Sweep clears the string out.
@@ -60,7 +60,7 @@ func Squeeze(argv0 string, argv1 byte) string {
6060
func Sweep(argv1 string) string {
6161
if argv1 == "" { return "" }
6262

63-
argv1 = Squeeze(strings.TrimSpace(strings.ReplaceAll(argv1, "\t", " ")), ' ')
63+
argv1 = strings.TrimSpace(strings.ReplaceAll(argv1, "\t", " ")); Squeeze(&argv1, ' ')
6464
for strings.Contains(argv1, " --") {
6565
// Delete all the string after a boundary string like " --neko-chan"
6666
if strings.Contains(argv1, "-- ") { break }

rfc3834/lib.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func Inquire(bf *sis.BeforeFact) sis.RisingUnderway {
8282
}
8383
if recipients == 0 { return sis.RisingUnderway{} }
8484

85-
// Squeeze continuous "\n" in the message body
86-
bf.Payload = strings.Trim(moji.Squeeze(bf.Payload, '\n'), "\n")
85+
moji.Squeeze(&bf.Payload, '\n') // Squeeze continuous "\n" in the message body
86+
bf.Payload = strings.Trim(bf.Payload, "\n")
8787
bodyslices := strings.Split(bf.Payload, "\n")
8888
rfc822part := ""
8989

rfc5322/headers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Headers(argv0 *mail.Header, argv1 bool) map[string][]string {
3939
// Do not include the value of Received: header generated by qmail or qmail-clone
4040
continue
4141
}
42-
e = moji.Squeeze(e, ' ')
42+
moji.Squeeze(&e, ' ')
4343
receivedby = append(receivedby, e)
4444
}
4545
headermaps["received"] = receivedby

0 commit comments

Comments
 (0)