MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / cleanupSemanticsScore

Function cleanupSemanticsScore

src/plugins/git/utils/differ.cpp:168–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168static int cleanupSemanticsScore(const QString &text1, const QString &text2)
169{
170 const QRegularExpression blankLineEnd("\\n\\r?\\n$");
171 const QRegularExpression blankLineStart("^\\r?\\n\\r?\\n");
172 const QRegularExpression sentenceEnd("\\. $");
173
174 if (text1.isEmpty() || text2.isEmpty()) // Edges
175 return 6;
176
177 const QChar char1 = text1[text1.size() - 1];
178 const QChar char2 = text2[0];
179 const bool nonAlphaNumeric1 = !char1.isLetterOrNumber();
180 const bool nonAlphaNumeric2 = !char2.isLetterOrNumber();
181 const bool whitespace1 = nonAlphaNumeric1 && char1.isSpace();
182 const bool whitespace2 = nonAlphaNumeric2 && char2.isSpace();
183 const bool lineBreak1 = whitespace1 && char1.category() == QChar::Other_Control;
184 const bool lineBreak2 = whitespace2 && char2.category() == QChar::Other_Control;
185 const bool blankLine1 = lineBreak1 && blankLineEnd.match(text1).hasMatch();
186 const bool blankLine2 = lineBreak2 && blankLineStart.match(text2).hasMatch();
187
188 if (blankLine1 || blankLine2) // Blank lines
189 return 5;
190 if (lineBreak1 || lineBreak2) // Line breaks
191 return 4;
192 if (sentenceEnd.match(text1).hasMatch()) // End of sentence
193 return 3;
194 if (whitespace1 || whitespace2) // Whitespaces
195 return 2;
196 if (nonAlphaNumeric1 || nonAlphaNumeric2) // Non-alphanumerics
197 return 1;
198
199 return 0;
200}
201
202static bool isWhitespace(const QChar &c)
203{

Callers 1

Calls 4

categoryMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected