Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: src/ports/SkFontMgr_android_parser.h

Issue 1306443004: Use static_assert instead of SK_COMPILE_ASSERT. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkFontMgr_android_parser_DEFINED 8 #ifndef SkFontMgr_android_parser_DEFINED
9 #define SkFontMgr_android_parser_DEFINED 9 #define SkFontMgr_android_parser_DEFINED
10 10
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 } // SkFontMgr_Android_Parser namespace 120 } // SkFontMgr_Android_Parser namespace
121 121
122 122
123 /** Parses a null terminated string into an integer type, checking for overflow. 123 /** Parses a null terminated string into an integer type, checking for overflow.
124 * http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-nega tive-def 124 * http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-nega tive-def
125 * 125 *
126 * If the string cannot be parsed into 'value', returns false and does not chan ge 'value'. 126 * If the string cannot be parsed into 'value', returns false and does not chan ge 'value'.
127 */ 127 */
128 template <typename T> static bool parse_non_negative_integer(const char* s, T* v alue) { 128 template <typename T> static bool parse_non_negative_integer(const char* s, T* v alue) {
129 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer); 129 static_assert(std::numeric_limits<T>::is_integer, "T_must_be_integer");
130 130
131 if (*s == '\0') { 131 if (*s == '\0') {
132 return false; 132 return false;
133 } 133 }
134 134
135 const T nMax = std::numeric_limits<T>::max() / 10; 135 const T nMax = std::numeric_limits<T>::max() / 10;
136 const T dMax = std::numeric_limits<T>::max() - (nMax * 10); 136 const T dMax = std::numeric_limits<T>::max() - (nMax * 10);
137 T n = 0; 137 T n = 0;
138 for (; *s; ++s) { 138 for (; *s; ++s) {
139 // Check if digit 139 // Check if digit
(...skipping 16 matching lines...) Expand all
156 * Like http://www.w3.org/TR/html-markup/datatypes.html#common.data.float-def , 156 * Like http://www.w3.org/TR/html-markup/datatypes.html#common.data.float-def ,
157 * but may start with '.' and does not support 'e'. '-?((:digit:+(.:digit:+)?)| (.:digit:+))' 157 * but may start with '.' and does not support 'e'. '-?((:digit:+(.:digit:+)?)| (.:digit:+))'
158 * 158 *
159 * Checks for overflow. 159 * Checks for overflow.
160 * Low bit rounding is not defined (is currently truncate). 160 * Low bit rounding is not defined (is currently truncate).
161 * Bias (N) required to allow for the sign bit and 4 bits of integer. 161 * Bias (N) required to allow for the sign bit and 4 bits of integer.
162 * 162 *
163 * If the string cannot be parsed into 'value', returns false and does not chan ge 'value'. 163 * If the string cannot be parsed into 'value', returns false and does not chan ge 'value'.
164 */ 164 */
165 template <int N, typename T> static bool parse_fixed(const char* s, T* value) { 165 template <int N, typename T> static bool parse_fixed(const char* s, T* value) {
166 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer); 166 static_assert(std::numeric_limits<T>::is_integer, "T_must_be_integer");
167 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_signed, T_must_be_signed); 167 static_assert(std::numeric_limits<T>::is_signed, "T_must_be_signed");
168 SK_COMPILE_ASSERT(sizeof(T) * CHAR_BIT - N >= 5, N_must_leave_four_bits_plus _sign); 168 static_assert(sizeof(T) * CHAR_BIT - N >= 5, "N_must_leave_four_bits_plus_si gn");
169 169
170 bool negate = false; 170 bool negate = false;
171 if (*s == '-') { 171 if (*s == '-') {
172 ++s; 172 ++s;
173 negate = true; 173 negate = true;
174 } 174 }
175 if (*s == '\0') { 175 if (*s == '\0') {
176 return false; 176 return false;
177 } 177 }
178 178
(...skipping 30 matching lines...) Expand all
209 } 209 }
210 if (negate) { 210 if (negate) {
211 n = -n; 211 n = -n;
212 frac = -frac; 212 frac = -frac;
213 } 213 }
214 *value = (n << N) + frac; 214 *value = (n << N) + frac;
215 return true; 215 return true;
216 } 216 }
217 217
218 #endif /* SkFontMgr_android_parser_DEFINED */ 218 #endif /* SkFontMgr_android_parser_DEFINED */
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_win.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698