@matheusbsbs / matheus-bagliano / commits / cfd432e63d
Fork 0

Remove ranges from switch statements.

Though very nice and readable, the "case 'a'...'z':" construct is not ANSI C99 compliant. This patch unfolds the range in `quote.c' and substitutes the switch-statement with an if-statement in `http-fetch.c' and `http-push.c'. Signed-off-by: Florian Forster <octo@verplant.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Florian Forster committed Jun 18, 2006 at 17:18 UTC cfd432e63d77478d913497a62827ed95c56dda73
3 files changed +22 -13
http-fetch.c
+7 -6
@@ -1136,13 +1136,14 @@ int fetch(unsigned char *sha1)
1136
1137 static inline int needs_quote(int ch)
1138 {
1139 - switch (ch) {
1140 - case '/': case '-': case '.':
1141 - case 'A'...'Z': case 'a'...'z': case '0'...'9':
1139 + if (((ch >= 'A') && (ch <= 'Z'))
1140 + || ((ch >= 'a') && (ch <= 'z'))
1141 + || ((ch >= '0') && (ch <= '9'))
1142 + || (ch == '/')
1143 + || (ch == '-')
1144 + || (ch == '.'))
1145 return 0;
1143 - default:
1144 - return 1;
1145 - }
1146 + return 1;
1147 }
1148
1149 static inline int hex(int v)
http-push.c
+7 -6
@@ -1077,13 +1077,14 @@ static int fetch_indices(void)
1077
1078 static inline int needs_quote(int ch)
1079 {
1080 - switch (ch) {
1081 - case '/': case '-': case '.':
1082 - case 'A'...'Z': case 'a'...'z': case '0'...'9':
1080 + if (((ch >= 'A') && (ch <= 'Z'))
1081 + || ((ch >= 'a') && (ch <= 'z'))
1082 + || ((ch >= '0') && (ch <= '9'))
1083 + || (ch == '/')
1084 + || (ch == '-')
1085 + || (ch == '.'))
1086 return 0;
1084 - default:
1085 - return 1;
1086 - }
1087 + return 1;
1088 }
1089
1090 static inline int hex(int v)
quote.c
+8 -1
@@ -206,7 +206,14 @@ char *unquote_c_style(const char *quoted, const char **endp)
206 case '\\': case '"':
207 break; /* verbatim */
208
209 - case '0'...'7':
209 + case '0':
210 + case '1':
211 + case '2':
212 + case '3':
213 + case '4':
214 + case '5':
215 + case '6':
216 + case '7':
217 /* octal */
218 ac = ((ch - '0') << 6);
219 if ((ch = *sp++) < '0' || '7' < ch)