Overview
Comment: | Coding style. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9276a1c3c801ef943aaf336cbed88ac9 |
User & Date: | js on 2012-10-08 08:12:04 |
Other Links: | manifest | tags |
Context
2012-10-09
| ||
14:59 | OFNumber: Make sure -[boolValue] is always a bool. check-in: 916ee17654 user: js tags: trunk | |
2012-10-08
| ||
08:12 | Coding style. check-in: 9276a1c3c8 user: js tags: trunk | |
2012-10-05
| ||
12:10 | OFDataArray: Support for string representations. check-in: 39c5a46ea5 user: js tags: trunk | |
Changes
Modified ObjFW.xcodeproj/project.pbxproj from [71c61ec738] to [5e09f71165].
︙ | ︙ | |||
500 501 502 503 504 505 506 | 4B3D23BB1337FC5800DD29B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 4B3D23EF1338008000DD29B8 /* mach_alias_list */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mach_alias_list; path = src/mach_alias_list; sourceTree = SOURCE_ROOT; }; 4B3D5693139A617D0010A78F /* OFSerializationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerializationTests.m; path = tests/OFSerializationTests.m; sourceTree = "<group>"; }; 4B45355113DCFE1E0037AB4D /* OFCountedSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCountedSet.h; path = src/OFCountedSet.h; sourceTree = "<group>"; }; 4B45355213DCFE1E0037AB4D /* OFCountedSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCountedSet.m; path = src/OFCountedSet.m; sourceTree = "<group>"; }; 4B48B95214DC23B100546D39 /* OFXMLProcessingInstructions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLProcessingInstructions.h; path = src/OFXMLProcessingInstructions.h; sourceTree = "<group>"; }; 4B48B95314DC23B100546D39 /* OFXMLProcessingInstructions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLProcessingInstructions.m; path = src/OFXMLProcessingInstructions.m; sourceTree = "<group>"; }; | < | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | 4B3D23BB1337FC5800DD29B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 4B3D23EF1338008000DD29B8 /* mach_alias_list */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mach_alias_list; path = src/mach_alias_list; sourceTree = SOURCE_ROOT; }; 4B3D5693139A617D0010A78F /* OFSerializationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerializationTests.m; path = tests/OFSerializationTests.m; sourceTree = "<group>"; }; 4B45355113DCFE1E0037AB4D /* OFCountedSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCountedSet.h; path = src/OFCountedSet.h; sourceTree = "<group>"; }; 4B45355213DCFE1E0037AB4D /* OFCountedSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCountedSet.m; path = src/OFCountedSet.m; sourceTree = "<group>"; }; 4B48B95214DC23B100546D39 /* OFXMLProcessingInstructions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLProcessingInstructions.h; path = src/OFXMLProcessingInstructions.h; sourceTree = "<group>"; }; 4B48B95314DC23B100546D39 /* OFXMLProcessingInstructions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLProcessingInstructions.m; path = src/OFXMLProcessingInstructions.m; sourceTree = "<group>"; }; 4B49EA65143B39CE0005BBC6 /* OFXMLNodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNodeTests.m; path = tests/OFXMLNodeTests.m; sourceTree = "<group>"; }; 4B49EA67143B3A090005BBC6 /* OFXMLCDATA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLCDATA.h; path = src/OFXMLCDATA.h; sourceTree = "<group>"; }; 4B49EA68143B3A090005BBC6 /* OFXMLCDATA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLCDATA.m; path = src/OFXMLCDATA.m; sourceTree = "<group>"; }; 4B49EA69143B3A090005BBC6 /* OFXMLCharacters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLCharacters.h; path = src/OFXMLCharacters.h; sourceTree = "<group>"; }; 4B49EA6A143B3A090005BBC6 /* OFXMLCharacters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLCharacters.m; path = src/OFXMLCharacters.m; sourceTree = "<group>"; }; 4B49EA6B143B3A090005BBC6 /* OFXMLComment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLComment.h; path = src/OFXMLComment.h; sourceTree = "<group>"; }; 4B49EA6C143B3A090005BBC6 /* OFXMLComment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLComment.m; path = src/OFXMLComment.m; sourceTree = "<group>"; }; |
︙ | ︙ | |||
538 539 540 541 542 543 544 | 4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+JSONValue.h"; path = "src/OFString+JSONValue.h"; sourceTree = "<group>"; }; 4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+JSONValue.m"; path = "src/OFString+JSONValue.m"; sourceTree = "<group>"; }; 4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_poll.h; path = src/OFStreamObserver_poll.h; sourceTree = "<group>"; }; 4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_poll.m; path = src/OFStreamObserver_poll.m; sourceTree = "<group>"; }; 4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_select.h; path = src/OFStreamObserver_select.h; sourceTree = "<group>"; }; 4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_select.m; path = src/OFStreamObserver_select.m; sourceTree = "<group>"; }; 4B6799561099E7C50041064A /* asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asprintf.h; path = src/asprintf.h; sourceTree = "<group>"; }; | < | 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | 4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+JSONValue.h"; path = "src/OFString+JSONValue.h"; sourceTree = "<group>"; }; 4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+JSONValue.m"; path = "src/OFString+JSONValue.m"; sourceTree = "<group>"; }; 4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_poll.h; path = src/OFStreamObserver_poll.h; sourceTree = "<group>"; }; 4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_poll.m; path = src/OFStreamObserver_poll.m; sourceTree = "<group>"; }; 4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_select.h; path = src/OFStreamObserver_select.h; sourceTree = "<group>"; }; 4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_select.m; path = src/OFStreamObserver_select.m; sourceTree = "<group>"; }; 4B6799561099E7C50041064A /* asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asprintf.h; path = src/asprintf.h; sourceTree = "<group>"; }; 4B67995A1099E7C50041064A /* OFArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFArray.h; path = src/OFArray.h; sourceTree = "<group>"; }; 4B67995B1099E7C50041064A /* OFArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFArray.m; path = src/OFArray.m; sourceTree = "<group>"; }; 4B67995C1099E7C50041064A /* OFAutoreleasePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFAutoreleasePool.h; path = src/OFAutoreleasePool.h; sourceTree = "<group>"; }; 4B67995D1099E7C50041064A /* OFAutoreleasePool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFAutoreleasePool.m; path = src/OFAutoreleasePool.m; sourceTree = "<group>"; }; 4B6799601099E7C50041064A /* OFDataArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDataArray.h; path = src/OFDataArray.h; sourceTree = "<group>"; }; 4B6799611099E7C50041064A /* OFDataArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDataArray.m; path = src/OFDataArray.m; sourceTree = "<group>"; }; 4B6799621099E7C50041064A /* OFDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDictionary.h; path = src/OFDictionary.h; sourceTree = "<group>"; }; |
︙ | ︙ | |||
1068 1069 1070 1071 1072 1073 1074 | 4BBA36C411406AB700CBA3AC /* atomic.h */, 4BA9CFA315E129D30076DC74 /* autorelease.h */, 4B3D236D1337FB5800DD29B8 /* base64.h */, 4B3D236E1337FB5800DD29B8 /* base64.m */, 4B6AF96F10A8D40E0003FB0A /* iso_8859_15.m */, 4BE17AD812FD744C002CEB0B /* foundation-compat.m */, 4BBA36C511406AB700CBA3AC /* macros.h */, | < < | 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 | 4BBA36C411406AB700CBA3AC /* atomic.h */, 4BA9CFA315E129D30076DC74 /* autorelease.h */, 4B3D236D1337FB5800DD29B8 /* base64.h */, 4B3D236E1337FB5800DD29B8 /* base64.m */, 4B6AF96F10A8D40E0003FB0A /* iso_8859_15.m */, 4BE17AD812FD744C002CEB0B /* foundation-compat.m */, 4BBA36C511406AB700CBA3AC /* macros.h */, 4BF1BCBF11C9663F0025511F /* objfw-defs.h.in */, 4BB50DCF12F863C700C9393F /* of_asprintf.h */, 4BB50DD012F863C700C9393F /* of_asprintf.m */, 4BA355BC14879BF700442EF4 /* of_strptime.h */, 4BA355B914879BDD00442EF4 /* of_strptime.m */, 4B67998B1099E7C50041064A /* threading.h */, 4B67998C1099E7C50041064A /* unicode.h */, |
︙ | ︙ | |||
1380 1381 1382 1383 1384 1385 1386 | }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { | | | 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0450; }; buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "ObjFW" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( English, |
︙ | ︙ |
Modified src/OFConstantString.m from [ed50b3697e] to [f6854092bd].
︙ | ︙ | |||
33 34 35 36 37 38 39 | # import <objc/runtime.h> struct { struct class *isa, *super_class; const char *name; long version, info, instance_size; struct ivar_list *ivars; | | | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # import <objc/runtime.h> struct { struct class *isa, *super_class; const char *name; long version, info, instance_size; struct ivar_list *ivars; struct method_list **method_lists; struct cache *cache; struct protocol_list *protocols; const char *ivar_layout; struct class_ext *ext; } _OFConstantStringClassReference; #endif |
︙ | ︙ |
Modified src/asprintf.m from [dcf7698e7b] to [7f6485171e].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #include "config.h" #include <stdio.h> #include <stdlib.h> #include <stdarg.h> int | | | | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include "config.h" #include <stdio.h> #include <stdlib.h> #include <stdarg.h> int vasprintf(char **string, const char *format, va_list arguments) { int length; if ((length = vsnprintf(NULL, 0, format, arguments)) < 0) return length; if ((*string = malloc((size_t)length + 1)) == NULL) return -1; return vsnprintf(*string, (size_t)length + 1, format, arguments); } int asprintf(char **string, const char *format, ...) { int ret; va_list arguments; va_start(arguments, format); ret = vasprintf(string, format, arguments); va_end(arguments); return ret; } |
Modified src/foundation-compat.m from [5ec64d7fc7] to [a117c753c1].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ /* * This file replaces NSAutoreleasePool with OFAutoreleasePool when it is | > | | | | | | > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ /* * This file replaces NSAutoreleasePool with OFAutoreleasePool when it is * linked. * This is done so there is no conflict because OFBlocks are used (blocks are * OFBlocks as soon as ObjFW is linked). An application expecting an NSBlock, * but getting an OFBlock because ObjFW is linked, would fail to autorelease * the block otherwise, as the block would be in an OFAutoreleasePool. By * replacing NSAutoreleasePool with OFAutoreleasePool, the application will * still properly free the autoreleased block. * With autorelease pools now being part of the runtime, this is not really * necessary anymore, as both, ObjFW and Foundation, use the runtime's pools if * available. However, this is kept for compatibility with older versions of * OS X, which don't ship with a runtime with autorelease pools. */ #include "config.h" #import <objc/runtime.h> #import "OFAutoreleasePool.h" |
︙ | ︙ |
Modified src/of_asprintf.m from [31d446cae5] to [a758901adf].
︙ | ︙ | |||
32 33 34 35 36 37 38 | #import "autorelease.h" #import "macros.h" #define MAX_SUBFORMAT_LEN 64 struct context { const char *format; | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | > | > | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | #import "autorelease.h" #import "macros.h" #define MAX_SUBFORMAT_LEN 64 struct context { const char *format; size_t format_len; char subformat[MAX_SUBFORMAT_LEN + 1]; size_t subformat_len; va_list arguments; char *buffer; size_t buffer_len; size_t i, last; enum { STATE_STRING, STATE_FORMAT_FLAGS, STATE_FORMAT_FIELD_WIDTH, STATE_FORMAT_LENGTH_MODIFIER, STATE_FORMAT_CONVERSION_SPECIFIER } state; enum { LENGTH_MODIFIER_NONE, LENGTH_MODIFIER_HH, LENGTH_MODIFIER_H, LENGTH_MODIFIER_L, LENGTH_MODIFIER_LL, LENGTH_MODIFIER_J, LENGTH_MODIFIER_Z, LENGTH_MODIFIER_T, LENGTH_MODIFIER_CAPITAL_L } length_modifier; }; static bool append_string(struct context *ctx, const char *append, size_t append_len) { char *new_buf; if (append_len == 0) return true; if ((new_buf = realloc(ctx->buffer, ctx->buffer_len + append_len + 1)) == NULL) return false; memcpy(new_buf + ctx->buffer_len, append, append_len); ctx->buffer = new_buf; ctx->buffer_len += append_len; return true; } static bool append_subformat(struct context *ctx, const char *subformat, size_t subformat_len) { if (ctx->subformat_len + subformat_len > MAX_SUBFORMAT_LEN) return false; memcpy(ctx->subformat + ctx->subformat_len, subformat, subformat_len); ctx->subformat_len += subformat_len; ctx->subformat[ctx->subformat_len] = 0; return true; } static bool state_string(struct context *ctx) { if (ctx->format[ctx->i] == '%') { if (ctx->i > 0) if (!append_string(ctx, ctx->format + ctx->last, ctx->i - ctx->last)) return false; if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->last = ctx->i + 1; ctx->state = STATE_FORMAT_FLAGS; } return true; } static bool state_format_flags(struct context *ctx) { switch (ctx->format[ctx->i]) { case '-': case '+': case ' ': case '#': case '0': if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; break; default: ctx->state = STATE_FORMAT_FIELD_WIDTH; ctx->i--; break; } return true; } static bool state_format_field_width(struct context *ctx) { if ((ctx->format[ctx->i] >= '0' && ctx->format[ctx->i] <= '9') || ctx->format[ctx->i] == '*' || ctx->format[ctx->i] == '.') { if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; } else { ctx->state = STATE_FORMAT_LENGTH_MODIFIER; ctx->i--; } return true; } static bool state_format_length_modifier(struct context *ctx) { /* Only one allowed */ switch (ctx->format[ctx->i]) { case 'h': /* and also hh */ if (ctx->format_len > ctx->i + 1 && ctx->format[ctx->i + 1] == 'h') { if (!append_subformat(ctx, ctx->format + ctx->i, 2)) return false; ctx->i++; ctx->length_modifier = LENGTH_MODIFIER_HH; } else { if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->length_modifier = LENGTH_MODIFIER_H; } break; case 'l': /* and also ll */ if (ctx->format_len > ctx->i + 1 && ctx->format[ctx->i + 1] == 'l') { #ifndef _WIN32 if (!append_subformat(ctx, ctx->format + ctx->i, 2)) return false; #else if (!append_subformat(ctx, "I64", 3)) return false; #endif ctx->i++; ctx->length_modifier = LENGTH_MODIFIER_LL; } else { if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->length_modifier = LENGTH_MODIFIER_L; } break; case 'j': #ifndef _WIN32 if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; #else if (!append_subformat(ctx, "I64", 3)) return false; #endif ctx->length_modifier = LENGTH_MODIFIER_J; break; case 'z': #ifndef _WIN32 if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; #else if (!append_subformat(ctx, "I", 1)) return false; #endif ctx->length_modifier = LENGTH_MODIFIER_Z; break; case 't': #ifndef _WIN32 if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; #else if (!append_subformat(ctx, "I", 1)) return false; #endif ctx->length_modifier = LENGTH_MODIFIER_T; break; case 'L': if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->length_modifier = LENGTH_MODIFIER_CAPITAL_L; break; #ifdef _WIN32 case 'I': /* win32 strangeness (I64 instead of ll or j) */ if (ctx->formatLen > ctx->i + 2 && ctx->format[ctx->i + 1] == '6' && ctx->format[ctx->i + 2] == '4') { if (!append_subformat(ctx, ctx->format + ctx->i, 3)) return false; ctx->i += 2; ctx->lengthModifier = LENGTH_MODIFIER_LL; } else ctx->i--; break; #endif #ifdef OF_IOS case 'q': /* iOS uses this for PRI?64 */ if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = LENGTH_MODIFIER_LL; break; #endif default: ctx->i--; break; } ctx->state = STATE_FORMAT_CONVERSION_SPECIFIER; return true; } static bool state_format_conversion_specifier(struct context *ctx) { char *tmp = NULL; int tmp_len = 0; if (!append_subformat(ctx, ctx->format + ctx->i, 1)) return false; switch (ctx->format[ctx->i]) { case '@': ctx->subformat[ctx->subformat_len - 1] = 's'; @try { id object; if ((object = va_arg(ctx->arguments, id)) != nil) { void *pool = objc_autoreleasePoolPush(); tmp_len = asprintf(&tmp, ctx->subformat, [[object description] UTF8String]); objc_autoreleasePoolPop(pool); } else tmp_len = asprintf(&tmp, ctx->subformat, "(nil)"); } @catch (id e) { free(ctx->buffer); @throw e; } break; case 'd': case 'i': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_HH: case LENGTH_MODIFIER_H: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case LENGTH_MODIFIER_L: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long)); break; case LENGTH_MODIFIER_LL: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long long)); break; case LENGTH_MODIFIER_J: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, intmax_t)); break; case LENGTH_MODIFIER_Z: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ssize_t)); break; case LENGTH_MODIFIER_T: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'o': case 'u': case 'x': case 'X': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_HH: case LENGTH_MODIFIER_H: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned int)); break; case LENGTH_MODIFIER_L: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long)); break; case LENGTH_MODIFIER_LL: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long long)); break; case LENGTH_MODIFIER_J: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, uintmax_t)); break; case LENGTH_MODIFIER_Z: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, size_t)); break; case LENGTH_MODIFIER_T: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_L: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, double)); break; case LENGTH_MODIFIER_CAPITAL_L: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long double)); break; default: return false; } break; case 'c': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case LENGTH_MODIFIER_L: #if WINT_MAX >= INT_MAX tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, wint_t)); #else tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); #endif break; default: return false; } break; case 's': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const char*)); break; case LENGTH_MODIFIER_L: tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const wchar_t*)); break; default: return false; } break; case 'p': if (ctx->length_modifier != LENGTH_MODIFIER_NONE) return false; tmp_len = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, void*)); break; case 'n': switch (ctx->length_modifier) { case LENGTH_MODIFIER_NONE: *va_arg(ctx->arguments, int*) = (int)ctx->buffer_len; break; case LENGTH_MODIFIER_HH: *va_arg(ctx->arguments, signed char*) = (signed char)ctx->buffer_len; break; case LENGTH_MODIFIER_H: *va_arg(ctx->arguments, short*) = (short)ctx->buffer_len; break; case LENGTH_MODIFIER_L: *va_arg(ctx->arguments, long*) = (long)ctx->buffer_len; break; case LENGTH_MODIFIER_LL: *va_arg(ctx->arguments, long long*) = (long long)ctx->buffer_len; break; case LENGTH_MODIFIER_J: *va_arg(ctx->arguments, intmax_t*) = (intmax_t)ctx->buffer_len; break; case LENGTH_MODIFIER_Z: *va_arg(ctx->arguments, size_t*) = (size_t)ctx->buffer_len; break; case LENGTH_MODIFIER_T: *va_arg(ctx->arguments, ptrdiff_t*) = (ptrdiff_t)ctx->buffer_len; break; default: return false; } break; case '%': if (ctx->length_modifier != LENGTH_MODIFIER_NONE) return false; if (!append_string(ctx, "%", 1)) return false; break; default: return false; } if (tmp_len == -1) return false; if (tmp != NULL) { if (!append_string(ctx, tmp, tmp_len)) { free(tmp); return false; } free(tmp); } memset(ctx->subformat, 0, MAX_SUBFORMAT_LEN); ctx->subformat_len = 0; ctx->length_modifier = LENGTH_MODIFIER_NONE; ctx->last = ctx->i + 1; ctx->state = STATE_STRING; return true; } static bool (*states[])(struct context*) = { state_string, state_format_flags, state_format_field_width, state_format_length_modifier, state_format_conversion_specifier }; int of_vasprintf(char **string, const char *format, va_list arguments) { struct context ctx; ctx.format = format; ctx.format_len = strlen(format); memset(ctx.subformat, 0, MAX_SUBFORMAT_LEN + 1); ctx.subformat_len = 0; va_copy(ctx.arguments, arguments); ctx.buffer_len = 0; ctx.last = 0; ctx.state = STATE_STRING; ctx.length_modifier = LENGTH_MODIFIER_NONE; if ((ctx.buffer = malloc(1)) == NULL) return -1; for (ctx.i = 0; ctx.i < ctx.format_len; ctx.i++) { if (!states[ctx.state](&ctx)) { free(ctx.buffer); return -1; } } if (ctx.state != STATE_STRING) { free(ctx.buffer); return -1; } if (!append_string(&ctx, ctx.format + ctx.last, ctx.format_len - ctx.last)) { free(ctx.buffer); return -1; } ctx.buffer[ctx.buffer_len] = 0; *string = ctx.buffer; return (ctx.buffer_len <= INT_MAX ? (int)ctx.buffer_len : -1); } int of_asprintf(char **string, const char *format, ...) { va_list arguments; int ret; va_start(arguments, format); ret = of_vasprintf(string, format, arguments); va_end(arguments); return ret; } |
Modified src/of_strptime.m from [635c1d9aeb] to [63b54ee0d2].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include <string.h> #include <time.h> const char* of_strptime(const char *buffer, const char *format, struct tm *tm) { | < > | | | | | | | | < | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <string.h> #include <time.h> const char* of_strptime(const char *buffer, const char *format, struct tm *tm) { enum { SEARCH_CONVERSION_SPECIFIER, IN_CONVERSION_SPECIFIER } state = SEARCH_CONVERSION_SPECIFIER; size_t i, j, buffer_len, format_len; buffer_len = strlen(buffer); format_len = strlen(format); for (i = j = 0; i < format_len; i++) { if (j >= buffer_len) return NULL; switch (state) { case SEARCH_CONVERSION_SPECIFIER: if (format[i] == '%') state = IN_CONVERSION_SPECIFIER; else if (format[i] != buffer[j++]) return NULL; break; case IN_CONVERSION_SPECIFIER:; int k, max_len, number = 0; switch (format[i]) { case 'd': case 'e': case 'H': case 'm': case 'M': case 'S': case 'y': max_len = 2; break; case 'Y': max_len = 4; break; case '%': case 'n': case 't': max_len = 0; break; default: return NULL; } if (max_len > 0 && (buffer[j] < '0' || buffer[j] > '9')) return NULL; for (k = 0; k < max_len && j < buffer_len && buffer[j] >= '0' && buffer[j] <= '9'; k++, j++) { number *= 10; number += buffer[j] - '0'; } switch (format[i]) { case 'd': |
︙ | ︙ |