OriginalPrefix[i] = IndentPrefix;
const unsigned SpacesInPrefix = llvm::count(IndentPrefix, ' ');
+ // This lambda also considers multibyte character that is not handled in
+ // functions like isPunctuation provided by CharInfo.
+ const auto NoSpaceBeforeFirstCommentChar = [&]() {
+ assert(Lines[i].size() > IndentPrefix.size());
+ const char FirstCommentChar = Lines[i][IndentPrefix.size()];
+ const unsigned FirstCharByteSize =
+ encoding::getCodePointNumBytes(FirstCommentChar, Encoding);
+ return encoding::columnWidth(
+ Lines[i].substr(IndentPrefix.size(), FirstCharByteSize),
+ Encoding) == 1 &&
+ (FirstCommentChar == '\\' || isPunctuation(FirstCommentChar) ||
+ isHorizontalWhitespace(FirstCommentChar));
+ };
+
// On the first line of the comment section we calculate how many spaces
// are to be added or removed, all lines after that just get only the
// change and we will not look at the maximum anymore. Additionally to the
OriginalPrefix[i - 1].rtrim(Blanks)) {
if (SpacesInPrefix < Style.SpacesInLineCommentPrefix.Minimum &&
Lines[i].size() > IndentPrefix.size() &&
- isAlphanumeric(Lines[i][IndentPrefix.size()])) {
+ !NoSpaceBeforeFirstCommentChar()) {
FirstLineSpaceChange =
Style.SpacesInLineCommentPrefix.Minimum - SpacesInPrefix;
} else if (SpacesInPrefix > Style.SpacesInLineCommentPrefix.Maximum) {
const auto FirstNonSpace = Lines[i][IndentPrefix.size()];
const auto AllowsSpaceChange =
SpacesInPrefix != 0 ||
- (isAlphanumeric(FirstNonSpace) ||
+ (!NoSpaceBeforeFirstCommentChar() ||
(FirstNonSpace == '}' && FirstLineSpaceChange != 0));
if (PrefixSpaceChange[i] > 0 && AllowsSpaceChange) {
"\n"
"/// Free Doxygen with 3 spaces\n"
"\n"
+ "//🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "// 🐉 Another nice dragon\n"
+ "\n"
+ "// \t Three leading spaces following tab\n"
+ "\n"
+ "// \\t Three leading spaces following backslash\n"
+ "\n"
"/// A Doxygen Comment with a nested list:\n"
"/// - Foo\n"
"/// - Bar\n"
"\n"
"/// Free Doxygen with 3 spaces\n"
"\n"
+ "// 🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "// 🐉 Another nice dragon\n"
+ "\n"
+ "// \t Three leading spaces following tab\n"
+ "\n"
+ "// \\t Three leading spaces following backslash\n"
+ "\n"
"/// A Doxygen Comment with a nested list:\n"
"/// - Foo\n"
"/// - Bar\n"
"\n"
"///Free Doxygen with 3 spaces\n"
"\n"
+ "//🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "//🐉 Another nice dragon\n"
+ "\n"
+ "//\t Three leading spaces following tab\n"
+ "\n"
+ "//\\t Three leading spaces following backslash\n"
+ "\n"
"///A Doxygen Comment with a nested list:\n"
"///- Foo\n"
"///- Bar\n"
"\n"
"/// Free Doxygen with 3 spaces\n"
"\n"
+ "// 🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "// 🐉 Another nice dragon\n"
+ "\n"
+ "// \t Three leading spaces following tab\n"
+ "\n"
+ "// \\t Three leading spaces following backslash\n"
+ "\n"
"/// A Doxygen Comment with a nested list:\n"
"/// - Foo\n"
"/// - Bar\n"
"\n"
"/// Free Doxygen with 3 spaces\n"
"\n"
+ "// 🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "// 🐉 Another nice dragon\n"
+ "\n"
+ "// \t Three leading spaces following tab\n"
+ "\n"
+ "// \\t Three leading spaces following backslash\n"
+ "\n"
"/// A Doxygen Comment with a nested list:\n"
"/// - Foo\n"
"/// - Bar\n"
"\n"
"///Free Doxygen with 3 spaces\n"
"\n"
+ "//🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "//🐉 Another nice dragon\n"
+ "\n"
+ "//\t Three leading spaces following tab\n"
+ "\n"
+ "//\\t Three leading spaces following backslash\n"
+ "\n"
"///A Doxygen Comment with a nested list:\n"
"///- Foo\n"
"///- Bar\n"
"\n"
"/// Free Doxygen with 3 spaces\n"
"\n"
+ "// 🐉 A nice dragon\n"
+ "\n"
+ "//\t abccba\n"
+ "\n"
+ "//\\t deffed\n"
+ "\n"
+ "// 🐉 Another nice dragon\n"
+ "\n"
+ "// \t Three leading spaces following tab\n"
+ "\n"
+ "// \\t Three leading spaces following backslash\n"
+ "\n"
"/// A Doxygen Comment with a nested list:\n"
"/// - Foo\n"
"/// - Bar\n"