[PATCH] D156796: [ADT] [NFC] Introduce isLower and isUpper helpers.

Jacek Caban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 07:20:11 PDT 2023


jacek created this revision.
jacek added reviewers: efriedma, jhenderson, MaskRay.
Herald added a project: All.
jacek requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

For D149095 <https://reviews.llvm.org/D149095>.


https://reviews.llvm.org/D156796

Files:
  llvm/include/llvm/ADT/StringExtras.h


Index: llvm/include/llvm/ADT/StringExtras.h
===================================================================
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -98,10 +98,14 @@
 /// Checks if character \p C is a hexadecimal numeric character.
 inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
 
+/// Checks if character \p C is a lowercase letter as classified by "C" locale.
+inline bool isLower(char C) { return 'a' <= C && C <= 'z'; }
+
+/// Checks if character \p C is a uppercase letter as classified by "C" locale.
+inline bool isUpper(char C) { return 'A' <= C && C <= 'Z'; }
+
 /// Checks if character \p C is a valid letter as classified by "C" locale.
-inline bool isAlpha(char C) {
-  return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z');
-}
+inline bool isAlpha(char C) { return isLower(C) || isUpper(C); }
 
 /// Checks whether character \p C is either a decimal digit or an uppercase or
 /// lowercase letter as classified by "C" locale.
@@ -137,14 +141,14 @@
 
 /// Returns the corresponding lowercase character if \p x is uppercase.
 inline char toLower(char x) {
-  if (x >= 'A' && x <= 'Z')
+  if (isUpper(x))
     return x - 'A' + 'a';
   return x;
 }
 
 /// Returns the corresponding uppercase character if \p x is lowercase.
 inline char toUpper(char x) {
-  if (x >= 'a' && x <= 'z')
+  if (isLower(x))
     return x - 'a' + 'A';
   return x;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156796.546041.patch
Type: text/x-patch
Size: 1426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230801/435d7a15/attachment.bin>


More information about the llvm-commits mailing list