Changeset 263 for trunk/ext/php

Show
Ignore:
Timestamp:
07/08/2007 13:30:54 (17 months ago)
Author:
indeyets
Message:

added some unit-tests, fixed loading of some data-types, added implicit bool and float-types

Location:
trunk/ext/php
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/TODO

    r262 r263  
    22General: 
    33  - "switch requirements to php 5.2 and remove redundant code" 
    4   - "write phpunit tests" 
     4  - "write more phpunit tests" 
    55  - "syck_load_from_file(string $url[, resource $context])" 
    66  - "syck_dump_to_file(string $url, mixed $data[, int $flags[, resource $context]])" 
     
    1010  - "Add support for datatypes": 
    1111    - "float#base60" 
    12     - "float#exp" 
    13     - "float#fix" 
    14     - "int#base60" 
    1512    - merge 
    1613    - "timestamp#iso8601" 
    1714    - "timestamp#spaced" 
    1815    - "timestamp#ymd" 
     16    - timestamp 
    1917  - objects: 
    2018    - "!php/hash:YAML::ClassName" 
  • trunk/ext/php/phpext.c

    r259 r263  
    195195                        } else if (strcmp(n->type_id, "bool#no") == 0) { 
    196196                                ZVAL_BOOL(o, 0); 
     197                        } else if (strcmp(n->type_id, "bool") == 0) { 
     198                                /* implicit boolean */ 
     199                                char *ptr = n->data.str->ptr; 
     200                                size_t len = n->data.str->len; 
     201 
     202                                if (len == 1) { 
     203                                        if (ptr[0] == 'y' || ptr[0] == 'Y') { 
     204                                                ZVAL_BOOL(o, 1); 
     205                                        } else if (ptr[0] == 'n' || ptr[0] == 'N') { 
     206                                                ZVAL_BOOL(o, 0); 
     207                                        } 
     208                                } else if (len == 2) { 
     209                                        if (strncmp(ptr, "on", len) == 0 || strncmp(ptr, "On", len) == 0 || strncmp(ptr, "ON", len) == 0) { 
     210                                                ZVAL_BOOL(o, 1); 
     211                                        } else if (strncmp(ptr, "no", len) == 0 || strncmp(ptr, "No", len) == 0 || strncmp(ptr, "NO", len) == 0) { 
     212                                                ZVAL_BOOL(o, 0); 
     213                                        } 
     214                                } else if (len == 3) { 
     215                                        if (strncmp(ptr, "yes", len) == 0 || strncmp(ptr, "Yes", len) == 0 || strncmp(ptr, "YES", len) == 0) { 
     216                                                ZVAL_BOOL(o, 1); 
     217                                        } else if (strncmp(ptr, "off", len) == 0 || strncmp(ptr, "Off", len) == 0 || strncmp(ptr, "OFF", len) == 0) { 
     218                                                ZVAL_BOOL(o, 0); 
     219                                        } 
     220                                } else if (len == 4) { 
     221                                        if (strncmp(ptr, "true", len) == 0 || strncmp(ptr, "True", len) == 0 || strncmp(ptr, "TRUE", len) == 0) { 
     222                                                ZVAL_BOOL(o, 1); 
     223                                        } 
     224                                } else if (len == 3) { 
     225                                        if (strncmp(ptr, "false", len) == 0 || strncmp(ptr, "False", len) == 0 || strncmp(ptr, "FALSE", len) == 0) { 
     226                                                ZVAL_BOOL(o, 1); 
     227                                        } 
     228                                } 
     229 
     230                                if (Z_TYPE_P(o) != IS_BOOL) { 
     231                                        zend_throw_exception_ex(syck_exception_entry, 0 TSRMLS_CC, "!bool specified, but value \"%s\" (len=%d) is incorrect on line %d, col %d: '%s'", ptr, len, p->linect, p->cursor - p->lineptr, p->lineptr); 
     232                                } 
    197233                        } else if (strcmp(n->type_id, "int#hex") == 0) { 
     234                                syck_str_blow_away_commas(n); 
    198235                                long intVal = strtol(n->data.str->ptr, NULL, 16); 
    199236                                ZVAL_LONG(o, intVal); 
     237                        } else if (strcmp(n->type_id, "int#base60") == 0) { 
     238                                char *ptr, *end; 
     239                                long sixty = 1; 
     240                                long total = 0; 
     241 
     242                                syck_str_blow_away_commas(n); 
     243                                ptr = n->data.str->ptr; 
     244                                end = n->data.str->ptr + n->data.str->len; 
     245 
     246                                while (end > ptr) { 
     247                                        long bnum = 0; 
     248                                        char *colon = end - 1; 
     249                                        while (colon >= ptr && *colon != ':') { 
     250                                            colon--; 
     251                                        } 
     252 
     253                                        if (colon >= ptr && *colon == ':') 
     254                                                *colon = '\0'; 
     255 
     256                                        bnum = strtol(colon + 1, NULL, 10); 
     257                                        total += bnum * sixty; 
     258                                        sixty *= 60; 
     259                                        end = colon; 
     260                                } 
     261 
     262                                ZVAL_LONG(o, total); 
    200263                        } else if (strcmp(n->type_id, "int#oct") == 0) { 
     264                                syck_str_blow_away_commas(n); 
    201265                                long intVal = strtol(n->data.str->ptr, NULL, 8); 
    202266                                ZVAL_LONG(o, intVal); 
    203267                        } else if (strcmp(n->type_id, "int") == 0) { 
     268                                syck_str_blow_away_commas(n); 
    204269                                long intVal = strtol(n->data.str->ptr, NULL, 10); 
    205270                                ZVAL_LONG(o, intVal); 
    206                         } else if (strcmp(n->type_id, "float") == 0) { 
     271                        } else if (strcmp(n->type_id, "float") == 0 || strcmp(n->type_id, "float#fix") == 0 || strcmp(n->type_id, "float#exp") == 0) { 
    207272                                double f; 
    208273                                syck_str_blow_away_commas(n); 
    209274                                f = strtod(n->data.str->ptr, NULL); 
     275 
     276                                ZVAL_DOUBLE(o, f); 
     277                        } else if (strcmp(n->type_id, "float#sixty") == 0) { 
     278                                double f; 
     279                                syck_str_blow_away_commas(n); 
     280                                f = strtod(n->data.str->ptr, NULL); 
     281 
    210282                                ZVAL_DOUBLE(o, f); 
    211283                        } else if (strcmp(n->type_id, "float#nan") == 0) { 
     
    448520        zval *ptr; 
    449521 
    450         if (ZEND_NUM_ARGS() != 1) { 
    451                 WRONG_PARAM_COUNT; 
    452         } 
    453  
    454522        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &ptr) == FAILURE) { 
    455523                return;