]> granicus.if.org Git - clang/commitdiff
Revert r187935 "Support for double width characters."
authorArnold Schwaighofer <aschwaighofer@apple.com>
Thu, 8 Aug 2013 02:19:56 +0000 (02:19 +0000)
committerArnold Schwaighofer <aschwaighofer@apple.com>
Thu, 8 Aug 2013 02:19:56 +0000 (02:19 +0000)
It broke a public build bot.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187957 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/BreakableToken.cpp
unittests/Format/FormatTest.cpp

index c2365f1402f7d8d6a8f50fbe90c4ce8815b35a47..3b2913779831ce47d4ac305b179ffa6f32d880e5 100644 (file)
@@ -20,7 +20,6 @@
 #include "clang/Format/Format.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/Locale.h"
 #include <algorithm>
 
 namespace clang {
@@ -39,15 +38,6 @@ static bool IsBlank(char C) {
   }
 }
 
-static unsigned columnWidth(StringRef Text, encoding::Encoding Encoding) {
-  if (Encoding == encoding::Encoding_UTF8) {
-    int ContentWidth = llvm::sys::locale::columnWidth(Text);
-    if (ContentWidth >= 0)
-      return ContentWidth;
-  }
-  return encoding::getCodePointCount(Text, Encoding);
-}
-
 static BreakableToken::Split getCommentSplit(StringRef Text,
                                              unsigned ContentStartColumn,
                                              unsigned ColumnLimit,
@@ -59,12 +49,9 @@ static BreakableToken::Split getCommentSplit(StringRef Text,
   unsigned MaxSplitBytes = 0;
 
   for (unsigned NumChars = 0;
-       NumChars < MaxSplit && MaxSplitBytes < Text.size();) {
-    unsigned NumBytes =
+       NumChars < MaxSplit && MaxSplitBytes < Text.size(); ++NumChars)
+    MaxSplitBytes +=
         encoding::getCodePointNumBytes(Text[MaxSplitBytes], Encoding);
-    NumChars += columnWidth(Text.substr(MaxSplitBytes, NumBytes), Encoding);
-    MaxSplitBytes += NumBytes;
-  }
 
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
   if (SpaceOffset == StringRef::npos ||
@@ -97,8 +84,9 @@ static BreakableToken::Split getStringSplit(StringRef Text,
     return BreakableToken::Split(StringRef::npos, 0);
   if (ColumnLimit <= ContentStartColumn)
     return BreakableToken::Split(StringRef::npos, 0);
-  unsigned MaxSplit = std::min<unsigned>(ColumnLimit - ContentStartColumn,
-                                         columnWidth(Text, Encoding) - 1);
+  unsigned MaxSplit =
+      std::min<unsigned>(ColumnLimit - ContentStartColumn,
+                         encoding::getCodePointCount(Text, Encoding) - 1);
   StringRef::size_type SpaceOffset = 0;
   StringRef::size_type SlashOffset = 0;
   StringRef::size_type WordStartOffset = 0;
@@ -110,7 +98,7 @@ static BreakableToken::Split getStringSplit(StringRef Text,
       Chars += Advance;
     } else {
       Advance = encoding::getCodePointNumBytes(Text[0], Encoding);
-      Chars += columnWidth(Text.substr(0, Advance), Encoding);
+      Chars += 1;
     }
 
     if (Chars > MaxSplit)
@@ -143,7 +131,7 @@ unsigned BreakableSingleLineToken::getLineCount() const { return 1; }
 unsigned BreakableSingleLineToken::getLineLengthAfterSplit(
     unsigned LineIndex, unsigned Offset, StringRef::size_type Length) const {
   return StartColumn + Prefix.size() + Postfix.size() +
-         columnWidth(Line.substr(Offset, Length), Encoding);
+         encoding::getCodePointCount(Line.substr(Offset, Length), Encoding);
 }
 
 BreakableSingleLineToken::BreakableSingleLineToken(
@@ -341,7 +329,8 @@ unsigned BreakableBlockComment::getLineCount() const { return Lines.size(); }
 unsigned BreakableBlockComment::getLineLengthAfterSplit(
     unsigned LineIndex, unsigned Offset, StringRef::size_type Length) const {
   return getContentStartColumn(LineIndex, Offset) +
-         columnWidth(Lines[LineIndex].substr(Offset, Length), Encoding) +
+         encoding::getCodePointCount(Lines[LineIndex].substr(Offset, Length),
+                                     Encoding) +
          // The last line gets a "*/" postfix.
          (LineIndex + 1 == Lines.size() ? 2 : 0);
 }
index 48b1f63fcad7385a2edc388c0e7829806e0f75c7..2969e568ebc618b73ab23f243ab1284939bc9900 100644 (file)
@@ -5704,15 +5704,15 @@ TEST_F(FormatTest, CountsUTF8CharactersProperly) {
   verifyFormat("\"Однажды в студёную зимнюю пору...\"",
                getLLVMStyleWithColumns(35));
   verifyFormat("\"一 二 三 四 五 六 七 八 九 十\"",
-               getLLVMStyleWithColumns(31));
+               getLLVMStyleWithColumns(21));
   verifyFormat("// Однажды в студёную зимнюю пору...",
                getLLVMStyleWithColumns(36));
   verifyFormat("// 一 二 三 四 五 六 七 八 九 十",
-               getLLVMStyleWithColumns(32));
+               getLLVMStyleWithColumns(22));
   verifyFormat("/* Однажды в студёную зимнюю пору... */",
                getLLVMStyleWithColumns(39));
   verifyFormat("/* 一 二 三 四 五 六 七 八 九 十 */",
-               getLLVMStyleWithColumns(35));
+               getLLVMStyleWithColumns(25));
 }
 
 TEST_F(FormatTest, SplitsUTF8Strings) {
@@ -5723,12 +5723,11 @@ TEST_F(FormatTest, SplitsUTF8Strings) {
       "\"пору,\"",
       format("\"Однажды, в студёную зимнюю пору,\"",
              getLLVMStyleWithColumns(13)));
-  EXPECT_EQ("\"一 二 三 \"\n"
-            "\"四 五六 \"\n"
-            "\"七 八 九 \"\n"
-            "\"十\"",
-            format("\"一 二 三 四 五六 七 八 九 十\"",
-                   getLLVMStyleWithColumns(11)));
+  EXPECT_EQ("\"一 二 三 四 \"\n"
+            "\"五 六 七 八 \"\n"
+            "\"九 十\"",
+            format("\"一 二 三 四 五 六 七 八 九 十\"",
+                   getLLVMStyleWithColumns(10)));
 }
 
 TEST_F(FormatTest, SplitsUTF8LineComments) {
@@ -5740,9 +5739,9 @@ TEST_F(FormatTest, SplitsUTF8LineComments) {
                    getLLVMStyleWithColumns(13)));
   EXPECT_EQ("// 一二三\n"
             "// 四五六七\n"
-            "// 八  九\n"
-            "// 十",
-            format("// 一二三 四五六七 八  九 十", getLLVMStyleWithColumns(9)));
+            "// 八\n"
+            "// 九 十",
+            format("// 一二三 四五六七 八  九 十", getLLVMStyleWithColumns(6)));
 }
 
 TEST_F(FormatTest, SplitsUTF8BlockComments) {
@@ -5759,17 +5758,16 @@ TEST_F(FormatTest, SplitsUTF8BlockComments) {
                    getLLVMStyleWithColumns(13)));
   EXPECT_EQ("/* 一二三\n"
             " * 四五六七\n"
-            " * 八  九\n"
-            " * 十  */",
-            format("/* 一二三 四五六七 八  九 十  */", getLLVMStyleWithColumns(9)));
+            " * 八\n"
+            " * 九 十\n"
+            " */",
+            format("/* 一二三 四五六七 八  九 十 */", getLLVMStyleWithColumns(6)));
   EXPECT_EQ("/* 𝓣𝓮𝓼𝓽 𝔣𝔬𝔲𝔯\n"
             " * 𝕓𝕪𝕥𝕖\n"
             " * 𝖀𝕿𝕱-𝟠 */",
             format("/* 𝓣𝓮𝓼𝓽 𝔣𝔬𝔲𝔯 𝕓𝕪𝕥𝕖 𝖀𝕿𝕱-𝟠 */", getLLVMStyleWithColumns(12)));
 }
 
-#endif // _MSC_VER
-
 TEST_F(FormatTest, FormatsWithWebKitStyle) {
   FormatStyle Style = getWebKitStyle();
 
@@ -5849,5 +5847,7 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
             format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style));
 }
 
+#endif
+
 } // end namespace tooling
 } // end namespace clang