[clang] [clang-format] Add functionality of getting info about numeric literals (PR #152878)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 11 08:39:10 PDT 2025


================
@@ -0,0 +1,65 @@
+//===--- NumericLiteralInfo.cpp ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements the functionality of getting information about a
+/// numeric literal string, including 0-based positions of the base letter, the
+/// decimal/hexadecimal point, the exponent letter, and the suffix, or npos if
+/// absent.
+///
+//===----------------------------------------------------------------------===//
+
+#include "NumericLiteralInfo.h"
+#include "llvm/ADT/StringExtras.h"
+
+namespace clang {
+namespace format {
+
+using namespace llvm;
+
+NumericLiteralInfo::NumericLiteralInfo(StringRef Text, char Separator) {
+  if (Text.size() < 2)
+    return;
+
+  bool IsHex = false;
+  if (Text[0] == '0') {
+    switch (Text[1]) {
+    case 'x':
+    case 'X':
+      IsHex = true;
+      [[fallthrough]];
+    case 'b':
+    case 'B':
+    case 'o':
----------------
owenca wrote:

Will do.

https://github.com/llvm/llvm-project/pull/152878


More information about the cfe-commits mailing list