[libcxx-commits] [PATCH] D112958: [libcxx][NFC] tidy up money_get::__do_get's sign parsing

Daniel McIntosh via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 4 14:55:48 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG41481b7db5c7: [libcxx][NFC] tidy up money_get::__do_get's sign parsing (authored by DanielMcIntosh-IBM).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112958/new/

https://reviews.llvm.org/D112958

Files:
  libcxx/include/locale


Index: libcxx/include/locale
===================================================================
--- libcxx/include/locale
+++ libcxx/include/locale
@@ -2892,51 +2892,31 @@
             }
             break;
         case money_base::sign:
-            if (__psn.size() + __nsn.size() > 0)
+            if (__psn.size() > 0 && *__b == __psn[0])
             {
-                if (__psn.size() == 0 || __nsn.size() == 0)
-                {   // sign is optional
-                    if (__psn.size() > 0)
-                    {   // __nsn.size() == 0
-                        if (*__b == __psn[0])
-                        {
-                            ++__b;
-                            if (__psn.size() > 1)
-                                __trailing_sign = &__psn;
-                        }
-                        else
-                            __neg = true;
-                    }
-                    else if (*__b == __nsn[0])  // __nsn.size() > 0 &&  __psn.size() == 0
-                    {
-                        ++__b;
-                        __neg = true;
-                        if (__nsn.size() > 1)
-                            __trailing_sign = &__nsn;
-                    }
-                }
-                else  // sign is required
-                {
-                    if (*__b == __psn[0])
-                    {
-                        ++__b;
-                        if (__psn.size() > 1)
-                            __trailing_sign = &__psn;
-                    }
-                    else if (*__b == __nsn[0])
-                    {
-                        ++__b;
-                        __neg = true;
-                        if (__nsn.size() > 1)
-                            __trailing_sign = &__nsn;
-                    }
-                    else
-                    {
-                        __err |= ios_base::failbit;
-                        return false;
-                    }
-                }
+                ++__b;
+                __neg = false;
+                if (__psn.size() > 1)
+                  __trailing_sign = &__psn;
+                break;
+            }
+            if (__nsn.size() > 0 && *__b == __nsn[0])
+            {
+                ++__b;
+                __neg = true;
+                if (__nsn.size() > 1)
+                    __trailing_sign = &__nsn;
+                break;
+            }
+            if (__psn.size() > 0 && __nsn.size() > 0)
+            {   // sign is required
+                __err |= ios_base::failbit;
+                return false;
             }
+            if (__psn.size() == 0 && __nsn.size() == 0)
+                // locale has no way of specifying a sign. Use the initial value of __neg as a default
+                break;
+            __neg = (__nsn.size() == 0);
             break;
         case money_base::symbol:
             {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112958.384874.patch
Type: text/x-patch
Size: 2866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211104/3354d5cb/attachment.bin>


More information about the libcxx-commits mailing list