@@ -78,59 +78,6 @@ func (r *Replacer) Compile() {
7878 r .engine = NewStringReplacer (r .Replacements ... )
7979}
8080
81- /*
82- line1 and line2 are different
83- extract words from each line1
84-
85- replace word -> newword
86- if word == new-word
87-
88- continue
89-
90- if new-word in list of replacements
91-
92- continue
93-
94- new word not original, and not in list of replacements some substring got mixed up. UNdo.
95- */
96- func (r * Replacer ) recheckLine (s string , lineNum int , buf io.Writer , next func (Diff )) {
97- first := 0
98- redacted := RemoveNotWords (s )
99-
100- idx := wordRegexp .FindAllStringIndex (redacted , - 1 )
101- for _ , ab := range idx {
102- word := s [ab [0 ]:ab [1 ]]
103- newword := r .engine .Replace (word )
104- if newword == word {
105- // no replacement done
106- continue
107- }
108-
109- // ignore camelCase words
110- // https://github.com/client9/misspell/issues/113
111- if CaseStyle (word ) == CaseUnknown {
112- continue
113- }
114-
115- if StringEqualFold (r .corrected [strings .ToLower (word )], newword ) {
116- // word got corrected into something we know
117- io .WriteString (buf , s [first :ab [0 ]])
118- io .WriteString (buf , newword )
119- first = ab [1 ]
120- next (Diff {
121- FullLine : s ,
122- Line : lineNum ,
123- Original : word ,
124- Corrected : newword ,
125- Column : ab [0 ],
126- })
127- continue
128- }
129- // Word got corrected into something unknown. Ignore it
130- }
131- io .WriteString (buf , s [first :])
132- }
133-
13481// ReplaceGo is a specialized routine for correcting Golang source files.
13582// Currently only checks comments, not identifiers for spelling.
13683func (r * Replacer ) ReplaceGo (input string ) (string , []Diff ) {
@@ -236,3 +183,56 @@ func (r *Replacer) ReplaceReader(raw io.Reader, w io.Writer, next func(Diff)) er
236183 }
237184 return nil
238185}
186+
187+ /*
188+ line1 and line2 are different
189+ extract words from each line1
190+
191+ replace word -> newword
192+ if word == new-word
193+
194+ continue
195+
196+ if new-word in list of replacements
197+
198+ continue
199+
200+ new word not original, and not in list of replacements some substring got mixed up. UNdo.
201+ */
202+ func (r * Replacer ) recheckLine (s string , lineNum int , buf io.Writer , next func (Diff )) {
203+ first := 0
204+ redacted := RemoveNotWords (s )
205+
206+ idx := wordRegexp .FindAllStringIndex (redacted , - 1 )
207+ for _ , ab := range idx {
208+ word := s [ab [0 ]:ab [1 ]]
209+ newword := r .engine .Replace (word )
210+ if newword == word {
211+ // no replacement done
212+ continue
213+ }
214+
215+ // ignore camelCase words
216+ // https://github.com/client9/misspell/issues/113
217+ if CaseStyle (word ) == CaseUnknown {
218+ continue
219+ }
220+
221+ if StringEqualFold (r .corrected [strings .ToLower (word )], newword ) {
222+ // word got corrected into something we know
223+ io .WriteString (buf , s [first :ab [0 ]])
224+ io .WriteString (buf , newword )
225+ first = ab [1 ]
226+ next (Diff {
227+ FullLine : s ,
228+ Line : lineNum ,
229+ Original : word ,
230+ Corrected : newword ,
231+ Column : ab [0 ],
232+ })
233+ continue
234+ }
235+ // Word got corrected into something unknown. Ignore it
236+ }
237+ io .WriteString (buf , s [first :])
238+ }
0 commit comments