llvm.org GIT mirror llvm / 8a53a83
Add llvm::hexDigitValue to convert single characters to hex. This is duplicated in a couple places in the codebase. Adopt this in APFloat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172851 91177308-0d34-0410-b5e6-96231b3b80d8 Jordan Rose 7 years ago
2 changed file(s) with 12 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
2424 static inline char hexdigit(unsigned X, bool LowerCase = false) {
2525 const char HexChar = LowerCase ? 'a' : 'A';
2626 return X < 10 ? '0' + X : HexChar + X - 10;
27 }
28
29 /// Interpret the given character \p C as a hexadecimal digit and return its
30 /// value.
31 ///
32 /// If \p C is not a valid hex digit, -1U is returned.
33 static inline unsigned hexDigitValue(char C) {
34 if (C >= '0' && C <= '9') return C-'0';
35 if (C >= 'a' && C <= 'f') return C-'a'+10U;
36 if (C >= 'A' && C <= 'F') return C-'A'+10U;
37 return -1U;
2738 }
2839
2940 /// utohex_buffer - Emit the specified number into the buffer specified by
1515 #include "llvm/ADT/APSInt.h"
1616 #include "llvm/ADT/FoldingSet.h"
1717 #include "llvm/ADT/Hashing.h"
18 #include "llvm/ADT/StringExtras.h"
1819 #include "llvm/ADT/StringRef.h"
1920 #include "llvm/Support/ErrorHandling.h"
2021 #include "llvm/Support/MathExtras.h"
9899 decDigitValue(unsigned int c)
99100 {
100101 return c - '0';
101 }
102
103 static unsigned int
104 hexDigitValue(unsigned int c)
105 {
106 unsigned int r;
107
108 r = c - '0';
109 if (r <= 9)
110 return r;
111
112 r = c - 'A';
113 if (r <= 5)
114 return r + 10;
115
116 r = c - 'a';
117 if (r <= 5)
118 return r + 10;
119
120 return -1U;
121102 }
122103
123104 /* Return the value of a decimal exponent of the form