Mercurial > vim
comparison src/typval.c @ 20925:0aeac2b45846 v8.2.1014
patch 8.2.1014: using "name" for a string result is confusing
Commit: https://github.com/vim/vim/commit/1e0b7b11db61bd906266d3174fee0bbaf20a101f
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jun 19 19:30:53 2020 +0200
patch 8.2.1014: using "name" for a string result is confusing
Problem: Using "name" for a string result is confusing.
Solution: Rename to "end".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 19 Jun 2020 19:45:03 +0200 |
parents | 8bce783af0cb |
children | 4d844a65183d |
comparison
equal
deleted
inserted
replaced
20924:c8f68af254b6 | 20925:0aeac2b45846 |
---|---|
1180 */ | 1180 */ |
1181 int | 1181 int |
1182 get_string_tv(char_u **arg, typval_T *rettv, int evaluate) | 1182 get_string_tv(char_u **arg, typval_T *rettv, int evaluate) |
1183 { | 1183 { |
1184 char_u *p; | 1184 char_u *p; |
1185 char_u *name; | 1185 char_u *end; |
1186 int extra = 0; | 1186 int extra = 0; |
1187 int len; | 1187 int len; |
1188 | 1188 |
1189 // Find the end of the string, skipping backslashed characters. | 1189 // Find the end of the string, skipping backslashed characters. |
1190 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) | 1190 for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) |
1214 return OK; | 1214 return OK; |
1215 } | 1215 } |
1216 | 1216 |
1217 // Copy the string into allocated memory, handling backslashed | 1217 // Copy the string into allocated memory, handling backslashed |
1218 // characters. | 1218 // characters. |
1219 rettv->v_type = VAR_STRING; | |
1219 len = (int)(p - *arg + extra); | 1220 len = (int)(p - *arg + extra); |
1220 name = alloc(len); | 1221 rettv->vval.v_string = alloc(len); |
1221 if (name == NULL) | 1222 if (rettv->vval.v_string == NULL) |
1222 return FAIL; | 1223 return FAIL; |
1223 rettv->v_type = VAR_STRING; | 1224 end = rettv->vval.v_string; |
1224 rettv->vval.v_string = name; | |
1225 | 1225 |
1226 for (p = *arg + 1; *p != NUL && *p != '"'; ) | 1226 for (p = *arg + 1; *p != NUL && *p != '"'; ) |
1227 { | 1227 { |
1228 if (*p == '\\') | 1228 if (*p == '\\') |
1229 { | 1229 { |
1230 switch (*++p) | 1230 switch (*++p) |
1231 { | 1231 { |
1232 case 'b': *name++ = BS; ++p; break; | 1232 case 'b': *end++ = BS; ++p; break; |
1233 case 'e': *name++ = ESC; ++p; break; | 1233 case 'e': *end++ = ESC; ++p; break; |
1234 case 'f': *name++ = FF; ++p; break; | 1234 case 'f': *end++ = FF; ++p; break; |
1235 case 'n': *name++ = NL; ++p; break; | 1235 case 'n': *end++ = NL; ++p; break; |
1236 case 'r': *name++ = CAR; ++p; break; | 1236 case 'r': *end++ = CAR; ++p; break; |
1237 case 't': *name++ = TAB; ++p; break; | 1237 case 't': *end++ = TAB; ++p; break; |
1238 | 1238 |
1239 case 'X': // hex: "\x1", "\x12" | 1239 case 'X': // hex: "\x1", "\x12" |
1240 case 'x': | 1240 case 'x': |
1241 case 'u': // Unicode: "\u0023" | 1241 case 'u': // Unicode: "\u0023" |
1242 case 'U': | 1242 case 'U': |
1259 } | 1259 } |
1260 ++p; | 1260 ++p; |
1261 // For "\u" store the number according to | 1261 // For "\u" store the number according to |
1262 // 'encoding'. | 1262 // 'encoding'. |
1263 if (c != 'X') | 1263 if (c != 'X') |
1264 name += (*mb_char2bytes)(nr, name); | 1264 end += (*mb_char2bytes)(nr, end); |
1265 else | 1265 else |
1266 *name++ = nr; | 1266 *end++ = nr; |
1267 } | 1267 } |
1268 break; | 1268 break; |
1269 | 1269 |
1270 // octal: "\1", "\12", "\123" | 1270 // octal: "\1", "\12", "\123" |
1271 case '0': | 1271 case '0': |
1273 case '2': | 1273 case '2': |
1274 case '3': | 1274 case '3': |
1275 case '4': | 1275 case '4': |
1276 case '5': | 1276 case '5': |
1277 case '6': | 1277 case '6': |
1278 case '7': *name = *p++ - '0'; | 1278 case '7': *end = *p++ - '0'; |
1279 if (*p >= '0' && *p <= '7') | 1279 if (*p >= '0' && *p <= '7') |
1280 { | 1280 { |
1281 *name = (*name << 3) + *p++ - '0'; | 1281 *end = (*end << 3) + *p++ - '0'; |
1282 if (*p >= '0' && *p <= '7') | 1282 if (*p >= '0' && *p <= '7') |
1283 *name = (*name << 3) + *p++ - '0'; | 1283 *end = (*end << 3) + *p++ - '0'; |
1284 } | 1284 } |
1285 ++name; | 1285 ++end; |
1286 break; | 1286 break; |
1287 | 1287 |
1288 // Special key, e.g.: "\<C-W>" | 1288 // Special key, e.g.: "\<C-W>" |
1289 case '<': | 1289 case '<': |
1290 { | 1290 { |
1291 int flags = FSK_KEYCODE | FSK_IN_STRING; | 1291 int flags = FSK_KEYCODE | FSK_IN_STRING; |
1292 | 1292 |
1293 if (p[1] != '*') | 1293 if (p[1] != '*') |
1294 flags |= FSK_SIMPLIFY; | 1294 flags |= FSK_SIMPLIFY; |
1295 extra = trans_special(&p, name, flags, NULL); | 1295 extra = trans_special(&p, end, flags, NULL); |
1296 if (extra != 0) | 1296 if (extra != 0) |
1297 { | 1297 { |
1298 name += extra; | 1298 end += extra; |
1299 if (name >= rettv->vval.v_string + len) | 1299 if (end >= rettv->vval.v_string + len) |
1300 iemsg("get_string_tv() used more space than allocated"); | 1300 iemsg("get_string_tv() used more space than allocated"); |
1301 break; | 1301 break; |
1302 } | 1302 } |
1303 } | 1303 } |
1304 // FALLTHROUGH | 1304 // FALLTHROUGH |
1305 | 1305 |
1306 default: MB_COPY_CHAR(p, name); | 1306 default: MB_COPY_CHAR(p, end); |
1307 break; | 1307 break; |
1308 } | 1308 } |
1309 } | 1309 } |
1310 else | 1310 else |
1311 MB_COPY_CHAR(p, name); | 1311 MB_COPY_CHAR(p, end); |
1312 | 1312 } |
1313 } | 1313 *end = NUL; |
1314 *name = NUL; | |
1315 if (*p != NUL) // just in case | 1314 if (*p != NUL) // just in case |
1316 ++p; | 1315 ++p; |
1317 *arg = p; | 1316 *arg = p; |
1318 | 1317 |
1319 return OK; | 1318 return OK; |