コード例 #1
0
ファイル: hlist.c プロジェクト: hailongz/c
void list_split_str(hlist_t hlist, hcchar * str,hcchar *split_chars,InvokeTickDeclare){
	if(hlist && str && split_chars){
		hchar * p = (hchar *)str;
		hchar *s = NULL;
		hbuffer_t buffer = buffer_alloc(1024, 1024);
		
		while(*p !='\0'){
			if(list_split_str_exist_char(split_chars,p,InvokeTickArg) ){
				if(buffer_length(buffer) > 0){
					s = NULL;
					str_cpy(&s, buffer_to_str(buffer));
					list_add(hlist, s,InvokeTickArg);
					buffer_clear(buffer);
				}
			}
			else{
				buffer_append(buffer, p, 1);
			}
			p++;
		}
		
		if(buffer_length(buffer) >0){
			s = NULL;
			str_cpy(&s, buffer_to_str(buffer));
			list_add(hlist, s,InvokeTickArg);
		}
		
		buffer_dealloc(buffer);
	}
}
コード例 #2
0
ファイル: hvmfile.c プロジェクト: hailongz/c
static vmVariant vmFileClassInitCallback(vmRuntimeContext context,vmClass * clazz,vmObject * object,vmVariantList args,InvokeTickDeclare){
    vmFile * file = (vmFile *) object;
    vmVariant rs=  {vmVariantTypeVoid,0};
    hbuffer_t bPath = buffer_alloc(128, 128);
    hbuffer_t bMode = buffer_alloc(32, 32);
    vmVariant path = vmVariantListGet(args, 0);
    vmVariant mode = vmVariantListGet(args, 1);
    
    vmVariantToString(context, path, bPath);
    vmVariantToString(context, mode, bMode);
    
    
    if(buffer_length(bPath) ==0){
        rs = vmRuntimeContextException(context, 0, "not found argument 1 file path");
    }
    
    if(rs.type == vmVariantTypeVoid){
        file->file = fopen(buffer_to_str(bPath), buffer_to_str(bMode));
    }
    
    if(!file->file){
        rs = vmRuntimeContextException(context, 0, "not found argument 2 file mode");
    }
    
    buffer_dealloc(bPath);
    buffer_dealloc(bMode);

    file->uniqueKeys.flush = vmRuntimeContextGetUniqueKey(context, "flush");
    file->uniqueKeys.read = vmRuntimeContextGetUniqueKey(context, "read");
    file->uniqueKeys.write = vmRuntimeContextGetUniqueKey(context, "write");
    file->uniqueKeys.seek = vmRuntimeContextGetUniqueKey(context, "seek");
    file->uniqueKeys.pos = vmRuntimeContextGetUniqueKey(context, "pos");
    
    return rs;
}
コード例 #3
0
ファイル: hvermin_bin.c プロジェクト: hailongz/c
static vmClassMetaOffset vmBinaryAddOperatorMeta(vmBinary * binary,vmCompileMetaOperator *op,InvokeTickDeclare){
    hint32 i,c;
    vmCompileMeta * meta;
    op->binary.offset = binary->operatorOffset;
    op->binary.uniqueKey = vmBinaryUniqueKey(binary,buffer_to_str(op->uniqueKey),hbool_false,InvokeTickArg);
    
    vmCompileObjectArrayAdd(binary->operatorMetas,op);
    
    c = vmCompileObjectArrayCount(op->compileMetas);
    
    op->binary.length = sizeof(vmRuntimeMetaOperator) + sizeof(vmRuntimeMeta) * c;
    
    binary->operatorOffset += op->binary.length;
    
    for(i=0;i<c;i++){
        meta = (vmCompileMeta *)vmCompileObjectArrayGet(op->compileMetas,i);
        if(meta->type & vmRuntimeMetaTypeOperator){
            meta->binary.valueOffset = vmBinaryAddOperatorMeta(binary, meta->value.operatorMeta,InvokeTickArg);
        }
        else if(meta->type & vmRuntimeMetaTypeString){
            meta->binary.valueOffset = vmBinaryUniqueKey(binary,buffer_to_str(meta->value.stringValue),hbool_true,InvokeTickArg);
        }
        else if(meta->type & vmRuntimeMetaTypeObject){
            meta->binary.valueOffset = vmBinaryUniqueKey(binary,buffer_to_str(meta->value.objectKey),hbool_false,InvokeTickArg);
        }
        else if(meta->type & vmRuntimeMetaTypeArg){
            meta->binary.valueOffset = vmBinaryUniqueKey(binary,buffer_to_str(meta->value.objectKey),hbool_false,InvokeTickArg);
        }
    }
    return op->binary.offset;
}
コード例 #4
0
ファイル: hvmsqlite.c プロジェクト: hailongz/c
static vmVariant vmSqliteClassInitCallback(vmRuntimeContext context,vmClass * clazz,vmObject * object,vmVariantList args,InvokeTickDeclare){
    vmVariant rs=  {vmVariantTypeVoid,0};
    vmSqlite * sqlite = (vmSqlite *) object;
    hbuffer_t file = buffer_alloc(128, 128);
    
    vmVariantToString(context, vmVariantListGet(args, 0), file);
    
    if(sqlite3_open(buffer_to_str(file), & sqlite->_sqlite)){
        
        rs = vmRuntimeContextException(context, sqlite3_errcode(sqlite->_sqlite), sqlite3_errmsg(sqlite->_sqlite));
        sqlite3_close(sqlite->_sqlite);
        
        sqlite->_sqlite = NULL;
    }
    
    buffer_dealloc(file);
    
    sqlite->uniqueKeys.exec = vmRuntimeContextGetUniqueKey(context, "exec");
    sqlite->uniqueKeys.query = vmRuntimeContextGetUniqueKey(context, "query");
    sqlite->uniqueKeys.lastRowId = vmRuntimeContextGetUniqueKey(context, "lastRowId");
    sqlite->uniqueKeys.encode = vmRuntimeContextGetUniqueKey(context, "encode");
    sqlite->uniqueKeys.sql = vmRuntimeContextGetUniqueKey(context, "sql");

    return rs;
}
コード例 #5
0
ファイル: CDExpNotEqual.cpp プロジェクト: hailongz/cpp
 Value * CDExpNotEqual::sql(const char * prefix,const char * suffix){
     InvokeTickBegin
     hbuffer_t buf = buffer_alloc(128, 128);
     Value * v = NULL;
     
     buffer_append_str(buf, "(");
     
     v = _left->sql(prefix, suffix);
     
     if(v){
         buffer_append_str(buf, v->stringValue());
     }
     
     buffer_append_str(buf, " <= ");
     
     v = _right->sql(prefix, suffix);
     
     if(v){
         buffer_append_str(buf, v->stringValue());
     }
     
     
     buffer_append_str(buf, ")");
     
     
     v = (Value *)(new Value(buffer_to_str(buf)))->autorelease();
     
     buffer_dealloc(buf);
     
     return v;
 }
コード例 #6
0
ファイル: Bundle.cpp プロジェクト: hailongz/cpp
 Value * Bundle::getStringContentV(const char * format,va_list va){
     Value * path = getFilePathV(format,va);
     
     if(_parent){
         return _parent->getStringContent(path->stringValue());
     }
     
     Value * v = NULL;
     InvokeTickBegin
     hbuffer_t content = buffer_alloc(512, 512);
     FILE * f = fopen(path->stringValue(), "r");
     char buffer[1024];
     int len;
     
     if(f){
         while((len = fread(buffer, 1, sizeof(buffer), f)) >0){
             buffer_append(content, buffer, len);
         }
         fclose(f);
     }
     
     v = Value::newValue(buffer_to_str(content));
     
     buffer_dealloc(content);
     
     return v;
 }
コード例 #7
0
ファイル: hdata.c プロジェクト: hailongz/c
void hdata_print_json(const hdata_class_t * data_class,hdata_t data,InvokeTickDeclare){
	if(data_class && DATA_STRUCT_ASSET(data)){
		hbuffer_t buffer = buffer_alloc(1024,  1024);
		hdata_write_json(data_class, data, buffer, hbool_true,InvokeTickArg);
		hlog("\n\n%s\n\n",buffer_to_str(buffer));
		buffer_dealloc(buffer);
	}
}
コード例 #8
0
ファイル: Bundle.cpp プロジェクト: hailongz/cpp
 Value * Bundle::getFilePathV(const char * format,va_list va){
     InvokeTickBegin
     hbuffer_t path = buffer_alloc(MAX_PATH, 128);
     Value * v = NULL;
     buffer_append_str(path,_bundlePath.c_str());
     if(buffer_length(path) >0 && * (buffer_data(path) + buffer_length(path) -1) != PATH_SPLIT){
         buffer_append_str(path, "/");
     }
     buffer_append_format_va_list(path, format, va);
     if(_parent){
         v = _parent->getFilePath(buffer_to_str(path));
     }
     else{
         v = Value::newValue(buffer_to_str(path));
     }
     buffer_dealloc(path);
     return v;
 }
コード例 #9
0
ファイル: hdata_xml.c プロジェクト: hailongz/c
static hdata_t hdata_xml_value_parse(hcchar * value,InvokeTickDeclare){
	hchar * p = (hchar *)value;
	hdouble double_value = 0;
	hbuffer_t decode_buffer;
	hdata_t data;
	
	if(TRUE_EQUAL(p)){
		return hdata_boolean_alloc( hbool_true);
	}
	else if(FALSE_EQUAL(p)){
		return hdata_boolean_alloc( hbool_false);
	}
	while(*p != '\0'){
		if(!NUMBER_CHAR(*p)){
			break;
		}
		p++;
	}
	if(p != '\0'){
		decode_buffer = buffer_alloc(1024, 1024);
		hdata_xml_value_decode(value,decode_buffer,InvokeTickArg);
		data = hdata_string_alloc( buffer_to_str(decode_buffer));
		buffer_dealloc(decode_buffer);
		return data;
	}
	else{
		sscanf(value, "%lf",&double_value);
		if((hint16)double_value == double_value){
			return hdata_int16_alloc((hint16)double_value );
		}
		else if((hint32)double_value == double_value){
			return hdata_int32_alloc((hint32)double_value );
		}
		else if((hint64)double_value == double_value){
			return hdata_int64_alloc((hint64)double_value );
		}
		else{
			return hdata_double_alloc( double_value);
		}
	}
}
コード例 #10
0
ファイル: hvermin_bin.c プロジェクト: hailongz/c
hbool vmBinaryAddClass(vmBinary * binary,vmCompileClassMeta * classMeta,hcchar * className,InvokeTickDeclare){
    hint32 i,c;
    classMeta->binary.className = vmBinaryUniqueKey(binary,className,hbool_true,InvokeTickArg);
    classMeta->binary.superClass = vmBinaryUniqueKey(binary, buffer_to_str(classMeta->superClass),hbool_true,InvokeTickArg);
    classMeta->binary.offset = binary->classOffset;
    vmCompileObjectArrayAdd(binary->classMetas,classMeta);
    

    c = vmCompileObjectArrayCount(classMeta->propertys);
    for(i=0;i<c;i++){
        vmBinaryAddOperatorMeta(binary,(vmCompileMetaOperator *)vmCompileObjectArrayGet(classMeta->propertys,i),InvokeTickArg);
    }
    
    c = vmCompileObjectArrayCount(classMeta->functions);
    for(i=0;i<c;i++){
        vmBinaryAddOperatorMeta(binary,(vmCompileMetaOperator *)vmCompileObjectArrayGet(classMeta->functions,i),InvokeTickArg);
    }
    
    binary->classOffset += sizeof(vmClassMeta) + vmCompileObjectArrayCount(classMeta->propertys) * sizeof(vmClassMetaOffset) + vmCompileObjectArrayCount(classMeta->functions) * sizeof(vmClassMetaOffset);
    
    return hbool_true;
}
コード例 #11
0
ファイル: init.c プロジェクト: medici/Scheme-1
static void define_recursive(buffer *ad_name, buffer *body, int depth,
                                env_hashtable *env) {
    buffer *expr_buffer,
           *new_ad_name,
           *new_body;
    char *expr_str;

    if (depth > 4)
        return;
    if (depth > 1) {
        expr_buffer = buffer_nprintf("(define c%br"
                                     " (lambda (x) %b))",
                                     ad_name,
                                     body);
        
        expr_str = buffer_to_str(expr_buffer);
        
        eval_str(expr_str, env);
        
        free(expr_str);
        free(expr_buffer);
    }

    new_ad_name = buffer_nprintf("a%b", ad_name);
    new_body = buffer_nprintf("(car %b)", body);

    define_recursive(new_ad_name, new_body, depth + 1, env);
    buffer_free(new_ad_name);
    buffer_free(new_body);

    new_ad_name = buffer_nprintf("d%b", ad_name);
    new_body = buffer_nprintf("(cdr %b)", body);

    define_recursive(new_ad_name, new_body, depth + 1, env);
    buffer_free(new_ad_name);
    buffer_free(new_body);
}
コード例 #12
0
ファイル: hvermin_bin.c プロジェクト: hailongz/c
vmRuntimeClassLibraryBytes * vmBinaryBytes(vmBinary * binary,InvokeTickDeclare){
    hint32 i,c,j,length;
    vmClassMetaOffset uniqueKeyOffset = 0;
    vmClassMetaOffset operatorOffset = 0;
    vmClassMetaOffset offset = 0,t;
    vmClassMetaOffset classOffset = 0;
    vmCompileClassMeta * classMeta;
    vmCompileMetaOperator *op;
    vmCompileMeta * meta;
    vmRuntimeClassLibraryBytes * bytes;
    vmRuntimeMetaOperator rOperator;
    vmRuntimeMeta rMeta;
    vmClassMeta rClassMeta;
    vmRuntimeClassMetaBytes bClassMeta;
    hchar *p;
    
    length = vmBinaryLength(binary,InvokeTickArg);
    
    bytes = mem_malloc(length);
    
    vmRuntimeClassLibraryBytesInit(bytes,InvokeTickArg);
    bytes->classCount = vmCompileObjectArrayCount(binary->classMetas);
    bytes->uniqueKeyCount = binary->uniqueKeyCount;
    

    
    uniqueKeyOffset = length - buffer_length(binary->uniqueKeys);
    
    mem_memcpy((hbyte *)bytes + uniqueKeyOffset, buffer_data(binary->uniqueKeys), buffer_length(binary->uniqueKeys));
    
    
    operatorOffset = uniqueKeyOffset - binary->operatorOffset;
    
    c = vmCompileObjectArrayCount(binary->operatorMetas);
    
    offset = operatorOffset;
    
    for(i=0;i<c;i++){
        op = (vmCompileMetaOperator *)vmCompileObjectArrayGet(binary->operatorMetas, i);
        mem_memset(&rOperator, 0, sizeof(vmRuntimeMetaOperator));
        rOperator.uniqueKey = op->binary.uniqueKey ? op->binary.uniqueKey + uniqueKeyOffset - UNIQUE_KEY_OFFSET : 0;
        rOperator.type = op->type;
        rOperator.metaCount = vmCompileObjectArrayCount(op->compileMetas);
        mem_memcpy((hbyte *)bytes + offset, &rOperator, sizeof(vmRuntimeMetaOperator));
        offset += sizeof(vmRuntimeMetaOperator);
        for(j=0;j<rOperator.metaCount;j++){
            meta = (vmCompileMeta *)vmCompileObjectArrayGet(op->compileMetas, j);
            mem_memset(&rMeta, 0, sizeof(vmRuntimeMeta));
            rMeta.type = meta->type;
            if(rMeta.type & vmRuntimeMetaTypeBoolean){
                rMeta.value.booleanValue = meta->value.booleanValue;
            }
            else if(rMeta.type & vmRuntimeMetaTypeInt16){
                rMeta.value.int16Value = meta->value.int16Value;
            }
            else if(rMeta.type & vmRuntimeMetaTypeInt32){
                rMeta.value.int32Value = meta->value.int32Value;
            }
            else if(rMeta.type & vmRuntimeMetaTypeInt64){
                rMeta.value.int64Value = meta->value.int64Value;
            }
            else if(rMeta.type & vmRuntimeMetaTypeDouble){
                rMeta.value.doubleValue = meta->value.doubleValue;
            }
            else if(rMeta.type & vmRuntimeMetaTypeString){
                rMeta.value.stringKey = meta->binary.valueOffset ? uniqueKeyOffset + meta->binary.valueOffset - UNIQUE_KEY_OFFSET : 0;
            }
            else if(rMeta.type & vmRuntimeMetaTypeObject){
                rMeta.value.objectKey = meta->binary.valueOffset ? uniqueKeyOffset + meta->binary.valueOffset - UNIQUE_KEY_OFFSET : 0;
            }
            else if(rMeta.type & vmRuntimeMetaTypeOperator){
                rMeta.value.operatorOffset = meta->binary.valueOffset ? operatorOffset + meta->binary.valueOffset: 0;
            }
            else if(rMeta.type & vmRuntimeMetaTypeArg){
                rMeta.value.objectKey = meta->binary.valueOffset ? uniqueKeyOffset + meta->binary.valueOffset - UNIQUE_KEY_OFFSET : 0;
            }
            mem_memcpy((hbyte *)bytes + offset, &rMeta, sizeof(vmRuntimeMeta));
            offset += sizeof(vmRuntimeMeta);
        }

    }
    
    classOffset = operatorOffset - binary->classOffset;
    offset = classOffset;
    
    c = vmCompileObjectArrayCount(binary->classMetas);
    
    for(i=0;i<c;i++){
        classMeta = (vmCompileClassMeta *) vmCompileObjectArrayGet(binary->classMetas, i);
        mem_memset(&rClassMeta, 0, sizeof(vmClassMeta));
        rClassMeta.type = vmClassTypeMeta;
        rClassMeta.superClass = classMeta->binary.superClass ? classMeta->binary.superClass + uniqueKeyOffset - UNIQUE_KEY_OFFSET : 0;
        rClassMeta.offset = offset;
        rClassMeta.propertys = vmCompileObjectArrayCount(classMeta->propertys);
        rClassMeta.functions = vmCompileObjectArrayCount(classMeta->functions);
        mem_memcpy((hbyte *)bytes + offset, &rClassMeta, sizeof(vmClassMeta));
        offset += sizeof(vmClassMeta);
        
        for(j=0;j<rClassMeta.propertys;j++){
            op = (vmCompileMetaOperator *) vmCompileObjectArrayGet(classMeta->propertys,j);
            t = operatorOffset + op->binary.offset;
            mem_memcpy((hbyte *)bytes + offset, &t, sizeof(vmClassMetaOffset));
            offset += sizeof(vmClassMetaOffset);
        }
        
        for(j=0;j<rClassMeta.functions;j++){
            op = (vmCompileMetaOperator *) vmCompileObjectArrayGet(classMeta->functions,j);
            t = operatorOffset + op->binary.offset;
            mem_memcpy((hbyte *)bytes + offset, &t, sizeof(vmClassMetaOffset));
            offset += sizeof(vmClassMetaOffset);
        }
    }
    
    offset = sizeof(vmRuntimeClassLibraryBytes);
    
    for(i=0;i<c;i++){
        classMeta = (vmCompileClassMeta *) vmCompileObjectArrayGet(binary->classMetas, i);
        mem_memset(&bClassMeta, 0, sizeof(vmRuntimeClassMetaBytes));
        bClassMeta.className = classMeta->binary.className ? classMeta->binary.className + uniqueKeyOffset - UNIQUE_KEY_OFFSET : 0;
        bClassMeta.classMeta = classOffset + classMeta->binary.offset;
        mem_memcpy((hbyte *)bytes + offset, &bClassMeta, sizeof(vmRuntimeClassMetaBytes));
        offset += sizeof(vmRuntimeClassMetaBytes);
    }
    
    p = (hchar *)buffer_to_str(binary->uniqueKeys);
    
    for(i=0;i<binary->uniqueKeyCount;i++){
        t = (vmClassMetaOffset)(uniqueKeyOffset + p - buffer_data(binary->uniqueKeys));
        mem_memcpy((hbyte *)bytes + offset, &t, sizeof(vmClassMetaOffset));
        offset += sizeof(vmClassMetaOffset);
        p += strlen(p) +1;
    }
    
    return bytes;
}
コード例 #13
0
ファイル: hvmsqlite.c プロジェクト: hailongz/c
/**
 
 Return : any
 */
static vmVariant vmSqliteClassInvokeCallback(vmRuntimeContext context,vmClass * clazz,vmObject * object,vmUniqueKey name,vmVariantList args,InvokeTickDeclare){
    vmVariant rs = {vmVariantTypeVoid,0};
    vmSqlite * sqlite = (vmSqlite *) object;
    
    if(!sqlite->_sqlite){
        return vmRuntimeContextException(context, 0, "not open sqlite file");
    }
    
    if(sqlite->uniqueKeys.exec == name){
        {
            hbuffer_t sql = buffer_alloc(128, 128);
            hchar * error = NULL;
            vmVariantToString(context, vmVariantListGet(args, 0), sql);
            
            sqlite3_exec(sqlite->_sqlite, buffer_to_str(sql), NULL, NULL, &error);
            
            if(error){
                rs = vmRuntimeContextException(context, sqlite3_errcode(sqlite->_sqlite), error);
            }
            
            buffer_dealloc(sql);
        }
    }
    else if(sqlite->uniqueKeys.query == name){
        {
            hbuffer_t sql = buffer_alloc(128, 128);
            hchar * error = NULL;
            hchar ** dbResult = NULL;
            hint32 nRow = 0;
            hint32 nColumn = 0;
            hint32 i,j;
            vmVariant row;
            vmVariant value;
            vmVariantToString(context, vmVariantListGet(args, 0), sql);
            
            sqlite3_get_table(sqlite->_sqlite, buffer_to_str(sql), &dbResult, &nRow, &nColumn, &error);

            
            if(error){
                sqlite3_free_table(dbResult);
                rs = vmRuntimeContextException(context, sqlite3_errcode(sqlite->_sqlite), error);
            }
            else{
                rs = vmArrayAlloc(context);
                for(i=0;i<nRow;i++){
                    row = vmDictionaryAlloc(context);
                    for(j=0;j<nColumn;j++){
                        value = vmStringAlloc(context, dbResult[nColumn + i * nColumn + j]);
                        vmDictionaryPut(context, row.value.objectValue, dbResult[j], value);
                    }
                    vmArrayAdd(context, rs.value.objectValue, row);
                }
                sqlite3_free_table(dbResult);
            }
            
            buffer_dealloc(sql);
        }
    }
    else if(sqlite->uniqueKeys.lastRowId == name){
        rs.type = vmVariantTypeInt64;
        rs.value.int64Value = sqlite3_last_insert_rowid(sqlite->_sqlite);
    }
    else if(sqlite->uniqueKeys.encode == name){
        {
            hbuffer_t str = buffer_alloc(128, 128);
            hbuffer_t enc = buffer_alloc(128, 128);
            vmVariant  var = vmVariantListGet(args, 0);
            hchar * p ;
            
            if(var.type != vmVariantTypeVoid){
                vmVariantToString(context, var, str);
                
                buffer_append_str(enc, "'");
                
                p = (hchar *)buffer_to_str(str);
                
                while(*p != 0){
                    
                    if( *p == '\''){
                        buffer_append_str(enc, "''");
                    }
                    else if( *p == '\t'){
                        buffer_append_str(enc, "\\t");
                    }
                    else if( *p == '\r'){
                        buffer_append_str(enc, "\\r");
                    }
                    else if( *p == '\n'){
                        buffer_append_str(enc, "\\n");
                    }
                    else{
                        buffer_append(enc,p,1);
                    }
                    
                    p ++;
                }
                
                buffer_append_str(enc, "'");
            }
            else{
                buffer_append_str(enc, "NULL");
            }
            
            rs =vmStringAlloc(context, buffer_to_str(enc));
            
            buffer_dealloc(str);
            buffer_dealloc(enc);
        }
    }
    else if(sqlite->uniqueKeys.sql == name){
        {
            hbuffer_t str = buffer_alloc(128, 128);
            hbuffer_t enc = buffer_alloc(128, 128);
            hbuffer_t key = buffer_alloc(64, 64);
            hbuffer_t value = buffer_alloc(128, 128);
            vmVariant var = vmVariantListGet(args, 0);
            vmVariant data = vmVariantListGet(args, 1);
            vmVariant v;
            hchar * p , *pp;
            hint32 s = 0;
            
            vmVariantToString(context, var, str);
            
            p = (hchar *)buffer_to_str(str);
            
            while(p){
                
                switch (s) {
                    case 0:
                    {
                        if(*p=='@'){
                            buffer_clear(key);
                            s = 1;
                        }
                        else{
                            buffer_append(enc,p,1);
                        }
                    }
                        break;
                    case 1:
                    {
                        if( ( *p >= 'A' && *p <= 'Z' ) || ( *p >= 'a' && *p <= 'z' ) || ( *p >= '0' && *p <= '9' ) || ( *p == '_' )){
                            buffer_append(key,p,1);
                        }
                        else{
                            if((data.type & vmVariantTypeObject) && data.value.objectValue){
                                v = vmObjectGetProperty(context, data.value.objectValue->vmClass, data.value.objectValue, vmRuntimeContextGetUniqueKey(context, buffer_to_str(key)));
                                if(v.type != vmVariantTypeVoid){
                                    buffer_clear(value);
                                    vmVariantToString(context, v, value);
                                    
                                    pp = (hchar *)buffer_to_str(value);
                                  
                                    buffer_append_str(enc, "'");
                                  
                                    while(*pp != 0){
                                        
                                        if( *pp == '\''){
                                            buffer_append_str(enc, "''");
                                        }
                                        else if( *pp == '\t'){
                                            buffer_append_str(enc, "\\t");
                                        }
                                        else if( *pp == '\r'){
                                            buffer_append_str(enc, "\\r");
                                        }
                                        else if( *pp == '\n'){
                                            buffer_append_str(enc, "\\n");
                                        }
                                        else{
                                            buffer_append(enc,pp,1);
                                        }
                                    
                                        pp ++;
                                    }
                                    
                                    buffer_append_str(enc, "'");
                                   
                                }
                                else{
                                    buffer_append_str(enc, "NULL");
                                }

                            }
                            else{
                                buffer_append_str(enc, "NULL");
                            }
                            buffer_append(enc,p,1);
                            s = 0;
                        }
                    }
                        break;
                    default:
                        break;
                }
                
                if(*p == '\0'){
                    break;
                }
                p ++;
            }
            
            
            rs = vmStringAlloc(context, buffer_to_str(enc));
            
            buffer_dealloc(value);
            buffer_dealloc(str);
            buffer_dealloc(enc);
            buffer_dealloc(key);
        }
    }
    
    return rs;
}
コード例 #14
0
ファイル: hvmfile.c プロジェクト: hailongz/c
/**
 
 Return : any
 */
static vmVariant vmFileClassInvokeCallback(vmRuntimeContext context,vmClass * clazz,vmObject * object,vmUniqueKey name,vmVariantList args,InvokeTickDeclare){
    vmVariant rs = {vmVariantTypeVoid,0};
    vmFile * file = (vmFile *) object;
    
    if(file->uniqueKeys.flush == name){
        if(file->file){
            fflush(file->file);
        }
    }
    else if(file->uniqueKeys.read == name){
        {
            hint32 length = vmVariantToInt32(context, vmVariantListGet(args, 0));
            hint32 len;
            hbyte buffer[1024];
            rs = vmDataAlloc(context, NULL, 0);
            if(length ==0){
                while(!feof(file->file) && (length = (hint32)fread(buffer, 1, sizeof(buffer), file->file))){
                    vmDataAppend(context, rs.value.objectValue, buffer, length);
                }
            }
            else if(length >0){
                len = sizeof(buffer);
                if(len > length){
                    len = length;
                }
                while(len >0 && !feof(file->file) && (len = (hint32)fread(buffer, 1, len, file->file))){
                    
                    vmDataAppend(context, rs.value.objectValue, buffer, len);
                    
                    length -= len;
                    len = sizeof(buffer);
                    if(len > length){
                        len = length;
                    }
                }
            }
        }
    }
    else if(file->uniqueKeys.write ==name){
        {
            vmVariant var = vmVariantListGet(args, 0);
            hbuffer_t buf = NULL;
            if(var.type & vmVariantTypeObject && var.value.objectValue && vmRuntimeContextObjectIsKindClass(context, var.value.objectValue, (vmClass *)&vmDataClass)){
                
                rs.type = vmVariantTypeInt32;
                rs.value.int32Value = (hint32)fwrite(vmDataDataPtr(context, var.value.objectValue), 1, vmDataDataLength(context, var.value.objectValue), file->file);
            }
            else if(var.type != vmVariantTypeVoid){
                buf = buffer_alloc(1024, 1024);
                
                vmVariantToString(context, var, buf);
                
                rs.type = vmVariantTypeInt32;
                
                rs.value.int32Value = (hint32)fwrite(buffer_data(buf), 1, buffer_length(buf), file->file);
                
                buffer_dealloc(buf);
            }
        }
    }
    else if(file->uniqueKeys.seek == name){
        
    }
    else if(file->uniqueKeys.flush == name){
        fflush(file->file);
    }
    else if(context->systemKeys.functionToStringKey == name){
        {
            hbuffer_t buf = buffer_alloc(128, 128);
            hbyte buffer[1024];
            ssize_t len;
            
            while(!feof(file->file) && (len = fread(buffer, 1, sizeof(buffer), file->file)) >0){
                buffer_append(buf, buffer, (hint32) len);
            }
        
            rs = vmStringAlloc(context, buffer_to_str(buf));
            
            buffer_dealloc(buf);
        }
    }
    return rs;
}
コード例 #15
0
ファイル: hdata_xml.c プロジェクト: hailongz/c
hdata_t hdata_xml_alloc(hcchar * xml_str,InvokeTickDeclare){
	hdata_t data = NULL,data_temp;
	hchar * p=(hchar *)xml_str;
	hstack_t data_stack = stack_alloc();
	hstack_t state_stack = stack_alloc();
	hbuffer_t tag_name_buffer = buffer_alloc(128,  256);
	hbuffer_t content_buffer = buffer_alloc(1024,  1024);
	hbuffer_t attr_name_buffer =buffer_alloc(128,  256);
	hbuffer_t attr_value_buffer = buffer_alloc(128,  256);
	hintptr s;
	hchar str_begin = 0;
	stack_push(state_stack, (hany) 0);
	stack_push(data_stack,hdata_array_alloc( 20, 20));
	
	while (*p != '\0') {
		s = (hintptr)stack_peek(state_stack);
		if(s == 0x00){
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '<' && p[1] == '?'){
				stack_push(state_stack, (hany)0x10);
				p++;
			}
			else if( *p == '<' && p[1] == '!'){
				stack_push(state_stack, (hany)0x11);
				p++;
			}
			else if( *p == '<' && p[1] == '/'){
				data_temp = stack_pop(data_stack);
				data = stack_pop(data_stack);
				if( hdata_array_size(&hdata_class, data_temp) ==0){
					hdata_object_remove(data, kCHILDS);
				}
				if(buffer_length(content_buffer) >0){
					hdata_object_put(data, kVALUE, hdata_xml_value_parse(buffer_to_str(content_buffer),InvokeTickArg));
					buffer_clear(content_buffer);
				}
				while( *p != '\0' && *p != '>'){
					p ++;
				}
				if(*p == '\0'){
					break;
				}
			}
			else if( *p == '<'){
				buffer_clear(content_buffer);
				buffer_clear(tag_name_buffer);
				data = hdata_object_alloc();
				hdata_array_add(stack_peek(data_stack), data);
				stack_push(data_stack, data);
				stack_push(state_stack, (hany)0x20);
			}
			else{
				buffer_append(content_buffer,p,1);
			}
		}
		else if(s ==0x10){
			// <? ?>
			if( p[0] == '?' && p[1] == '>'){
				p++;
				stack_pop(state_stack);
			}
		}
		else if(s == 0x11){
			// <!
			if(p[0] == '>' ){
				stack_pop(state_stack);
			}
		}
		else if(s == 0x20){
			// <tagname 
			if(SPACE_CHAR(*p)){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x21);
			}
			else if( *p == '/' && p[1] =='>'){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				stack_pop(data_stack);
				stack_pop(state_stack);
				p++;
			}
			else if( *p == '>'){
				hdata_object_put((hdata_t)stack_peek(data_stack), kTAGNAME, hdata_string_alloc( buffer_to_str(tag_name_buffer)));
				buffer_clear(tag_name_buffer);
				data = hdata_array_alloc( 20, 20);
				hdata_object_put(stack_peek(data_stack), kCHILDS, data);
				stack_push(data_stack, data);
				stack_pop(state_stack);
			}
			else{
				buffer_append(tag_name_buffer, p, 1);
			}
		}
		else if(s == 0x21){
			// <tagname attrname=
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '/' && p[1] =='>'){
				stack_pop(data_stack);
				stack_pop(state_stack);
				p++;
			}
			else if( *p == '>'){
				data = hdata_array_alloc( 20, 20);
				hdata_object_put(stack_peek(data_stack), kCHILDS, data);
				stack_push(data_stack, data);
				stack_pop(state_stack);
			}
			else if( *p == '='){
				stack_push(state_stack, (hany)0x22);
			}
			else {
				buffer_append(attr_name_buffer,p,1);
			}
		}
		else if(s == 0x22){
			// <tagname attrname=valuebegin
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '\''){
				str_begin = '\'';
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
			}
			else if( *p == '"'){
				str_begin = '"';
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
			}
			else {
				str_begin = 0;
				stack_pop(state_stack);
				stack_push(state_stack, (hany)0x23);
				buffer_append(attr_value_buffer, p, 1);
			}

		}
		else if( s == 0x23){
			// <tagname attrname=value
			if(str_begin ==0){
				if(SPACE_CHAR(*p)){
					hdata_object_put((hdata_t)stack_peek(data_stack),buffer_to_str(attr_name_buffer),hdata_xml_value_parse(buffer_to_str(attr_value_buffer),InvokeTickArg));
					buffer_clear(attr_name_buffer);
					buffer_append_str(attr_name_buffer, "@");
					buffer_clear(attr_value_buffer);
					stack_pop(state_stack);
				}
				else{
					buffer_append(attr_value_buffer, p, 1);
				}
			}
			else {
				if( p[0] == '\\' ){
					if(p[1] == '\\'){
						buffer_append_str(attr_value_buffer, "\\");
					}
					else if(p[1] == 'n'){
						buffer_append_str(attr_value_buffer, "\n");
					}
					else if(p[1] == 'r'){
						buffer_append_str(attr_value_buffer, "\r");
					}
					else if(p[1] == 't'){
						buffer_append_str(attr_value_buffer, "\t");
					}
					else if(p[1] == '"'){
						buffer_append_str(attr_value_buffer, "\"");
					}
					else if(p[1] == '\''){
						buffer_append_str(attr_value_buffer, "\'");
					}
					else{
						buffer_append(attr_value_buffer,p+1,1);
					}
					p ++;
				}
				else if( p[0] == str_begin){
					hdata_object_put((hdata_t)stack_peek(data_stack),buffer_to_str(attr_name_buffer),hdata_xml_value_parse(buffer_to_str(attr_value_buffer),InvokeTickArg));
					buffer_clear(attr_name_buffer);
					buffer_append_str(attr_name_buffer, "@");
					buffer_clear(attr_value_buffer);
					stack_pop(state_stack);
				}
				else{
					buffer_append(attr_value_buffer,p,1);
				}
			}
		}

		
		p++;
	}
	
	
	
	data = (hdata_t)stack_pop(data_stack);
	data_temp = (hdata_t)stack_pop(data_stack);
	
	while(data_temp){
		hdata_dealloc(data);
		data = data_temp;
		data_temp = (hdata_t)stack_pop(data_stack);
	}
	

	buffer_dealloc(tag_name_buffer);
	buffer_dealloc(content_buffer);
	buffer_dealloc(attr_name_buffer);
	buffer_dealloc(attr_value_buffer);
	stack_dealloc(data_stack);
	stack_dealloc(state_stack);
	
	return data;
}
コード例 #16
0
ファイル: hdata_xml.c プロジェクト: hailongz/c
void hdata_xpath(hdata_xpath_t data_xpath, hcchar * path,hlist_t result,hdata_xpath_selector_t parent_selector,InvokeTickDeclare){
	if(data_xpath && path){
		data_xpath_t * xpath = (data_xpath_t *)data_xpath;
		hchar * p = (hchar *)path,s = 0,r = 1;
		hbuffer_t selector_name = buffer_alloc(128,  128);
		hbuffer_t selector_exp = buffer_alloc(128,  128);
		
		data_xpath_selector_t * selector = parent_selector?(data_xpath_selector_t * )parent_selector:xpath->root;
		hlist_t selector_list = list_alloc( 10, 20);
		hint32 i,c;
		
		while(*p != '\0'){
			if(s ==0){
				if(SPACE_CHAR(*p)){
				}
				else if(*p == '/'){
					if(buffer_length(selector_name) >0){
						list_clear(selector_list);
						hdata_xpath_selctor(xpath,selector,selector_list,buffer_to_str(selector_name),buffer_to_str(selector_exp),r,InvokeTickArg);
						if(list_count(selector_list) ==0){
							break;
						}
						else{
							selector = list_get(selector_list, 0);
						}
						buffer_clear(selector_name);
						buffer_clear(selector_exp);
						r = !r;
					}
					else{
						r = !r;
					}
				}
				else if(*p == '['){
					s = 1;
				}
				else{
					buffer_append(selector_name, p, 1);
				}
			}
			else if(s == 1){
				if(*p == ']'){
					s = 0;
				}
				else{
					buffer_append(selector_exp,p,1);
				}
			}
			p++;
		}
		if(buffer_length(selector_name) >0){
			list_clear(selector_list);
			hdata_xpath_selctor(xpath,selector,selector_list,buffer_to_str(selector_name),buffer_to_str(selector_exp),r,InvokeTickArg);
			if(list_count(selector_list) !=0){
				selector = list_get(selector_list, 0);
			}
		}
		buffer_dealloc(selector_name);
		buffer_dealloc(selector_exp);
		c = list_count(selector_list);
		for(i=0;i<c;i++){
			selector = list_get(selector_list, i);
			list_add(result, selector);
		}
		list_dealloc(selector_list);
	}
}
コード例 #17
0
ファイル: hdata_xml.c プロジェクト: hailongz/c
static hint32 data_xpath_tag_filter_parse(hlist_t filters,hcchar * exp,InvokeTickDeclare){
	hint32 index = -1;
	hchar * p = (hchar *)exp,number =1,s=0;
	hbuffer_t name = buffer_alloc(128,  128);
	hbuffer_t value = buffer_alloc(128,  128);
	
	while(*p){
		
		if(s ==0){
			if(SPACE_CHAR(*p)){
			}
			else{
				buffer_append(name, p, 1);
				s = 1;
				if(number && !NUMBER_CHAR(*p)){
					number = 0;
				}
			}
		}
		else if(s == 1){
			//name
			if(SPACE_CHAR(*p)){
			}
			else if(*p == '='){
				s = 2;
				if(number && !NUMBER_CHAR(*p)){
					number = 0;
				}
			}
			else {
				buffer_append(name, p, 1);
				if(number && !NUMBER_CHAR(*p)){
					number = 0;
				}
			}
		}
		else if(s == 2){
			// value
			if( *p == ','){
				s =1;
				if(number && !NUMBER_CHAR(*p)){
					number = 0;
				}
				if(buffer_length(name) >0){
					list_add(filters, data_xpath_tag_filter_attr_alloc(buffer_to_str(name),buffer_to_str(value),InvokeTickArg));
				}
				buffer_clear(name);
				buffer_clear(value);
			}
			else {
				buffer_append(value, p, 1);
			}
		}
		
		p++;
	}
	
	if(buffer_length(name) >0){
		if(number){
			index = atoi(buffer_to_str(name));
		}
		else{
			if(buffer_length(name) >0){
				list_add(filters, data_xpath_tag_filter_attr_alloc(buffer_to_str(name),buffer_to_str(value),InvokeTickArg));
			}
		}
	}
	
	buffer_dealloc(name);
	buffer_dealloc(value);
	
	return index;
}
コード例 #18
0
ファイル: hjson.c プロジェクト: hailongz/c
hany hjson_decode(hjson_t * json,hcchar * str,InvokeTickDeclare){
    hany data = NULL;
	hchar * p=(hchar *)str;
	hlist_t data_stack = list_alloc(20,20);
	hlist_t state_stack =list_alloc(20,20);
	hbuffer_t value_buffer = buffer_alloc(128,  256);
	hbuffer_t name_buffer = buffer_alloc(128,  256);
    hbuffer_t base64_buffer= buffer_alloc(1024,1024);
	hintptr s;
    hwchar wchar;
    hint32 iwchar;
    hchar wchbuf[8];
	//hint32 object_level=0;
	//hint32 array_level =0;
	list_add(state_stack, (hany) 0);
	
	
	while (p && *p != '\0') {
		s = (hintptr)list_last(state_stack);
		if(s == 0x00){
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				list_add(data_stack, data);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p == '\"'){
				list_add(state_stack, (hany)0x01);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( FALSE_EQUAL(p)){
				data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else if( NULL_EQUAL(p)){
				data = (*json->nullValue)(json,InvokeTickArg);
				list_add(data_stack, data);
				break;
			}
			else{
				list_add(state_stack, (hany)0x02);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x01){
			// string value end
			data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s == 0x02){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
			list_add(data_stack, data);
			break;
		}
		else if(s ==0x10) {
			// object
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if(*p == '\"'){
				list_add(state_stack, (hany)0x11);
			}
			else if(*p == ':'){
				list_add(state_stack, (hany)0x12);
			}
			else if(*p == '}'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object end %ld\n",--object_level);
                
			}
			else{
				buffer_append(name_buffer,p,1);
				list_add(state_stack, (hany)0x11);
			}
		}
		else if(s == 0x11){
			// object value key
			if(*p == '\\' && p[1] == '"'){
				p++;
				buffer_append(name_buffer, p, 1);
			}
			else if( *p == '"'){
				list_pop(state_stack);
			}
			else if( *p == ':'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x12);
			}
			else{
				buffer_append(name_buffer, p, 1);
			}
		}
		else if(s == 0x12){
			// object value
			if(SPACE_CHAR(*p)){
			}
			else if( *p == '{'){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_pop(state_stack);
				list_add(state_stack, (hany)0x20);
				data = (*json->array_new)(json,InvokeTickArg);
				(*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
				list_add(data_stack, data);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_pop(state_stack);
				list_add(state_stack, (hany)0x13);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
				list_pop(state_stack);
                
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
				list_pop(state_stack);
                data = (*json->nullValue)(json,InvokeTickArg);
                (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
                
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				p += 3;
			}
			else {
				list_pop(state_stack);
				list_add(state_stack, (hany)0x14);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x13){
			// string value end
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x14){
			// number value end
			data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg);
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x20){
			// array value
			if(SPACE_CHAR(*p) || *p ==','){
			}
			else if( *p ==']'){
				list_pop(state_stack);
				list_pop(data_stack);
				buffer_clear(name_buffer);
				buffer_clear(value_buffer);
				//hlog("array end %ld\n",--array_level);
			}
			else if( *p == '{'){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x10);
				data = (*json->object_new)(json,InvokeTickArg);
                (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("object begin %ld\n",object_level++);
                
			}
			else if( *p == '['){
				list_add(state_stack, (hany)0x23);
				list_add(state_stack, (hany)0x20);
                data = (*json->array_new)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				list_add(data_stack, data);
				//hlog("array begin %ld\n",array_level++);
			}
			else if( *p =='"'){
				// string value
				list_add(state_stack, (hany)0x21);
				list_add(state_stack, (hany)0x30);
			}
			else if( TRUE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_true,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else if( FALSE_EQUAL(p)){
                data = (*json->booleanValue)(json,hbool_false,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 4;
			}
			else if( NULL_EQUAL(p)){
                data = (*json->nullValue)(json,InvokeTickArg);
				(*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
				p += 3;
			}
			else {
				list_add(state_stack, (hany)0x22);
				list_add(state_stack, (hany)0x40);
				continue;
			}
		}
		else if(s == 0x21){
			// string value end
            
            data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x22){
			// number value end
            data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg);
            (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg);
            
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s == 0x23){
			// object || array value end
			/*
             data = list_pop(data_stack);
             if(data ){
             hdata_array_add((hdata_t)list_last(data_stack), data);
             }
			 */
			buffer_clear(name_buffer);
			buffer_clear(value_buffer);
			list_pop(state_stack);
			continue;
		}
		else if(s ==0x30){
			// string value
			if( *p == '\\'){
				if( p[1] == 'n'){
					buffer_append_str(value_buffer,"\n");
				}
				else if( p[1] == 'r'){
					buffer_append_str(value_buffer,"\r");
				}
				else if( p[1] == 't'){
					buffer_append_str(value_buffer,"\t");
				}
				else if( p[1] == '\\'){
					buffer_append_str(value_buffer,"\\");
				}
				else if( p[1] == '\"'){
					buffer_append_str(value_buffer,"\"");
				}
				else if( p[1] == '\''){
					buffer_append_str(value_buffer,"\'");
				}
                else if( p[1] == 'u' ||  p[1] == 'U'){
                    iwchar = 0;
					sscanf(p + 2, "%04x",&iwchar);
                    wchar = iwchar;
                    strcpy(wchbuf, "");
                    buffer_append(value_buffer, wchbuf,wstr_to_str(&wchar, 1, wchbuf));
                    p+= 4;
				}
				else{
					buffer_append(value_buffer,p+1,1);
				}
				p++;
			}
			else if( *p == '\"'){
				list_pop(state_stack);
			}
			else{
				buffer_append(value_buffer,p,1);
			}
		}
		else if(s == 0x40){
			// number value
			if(NUMBER_CHAR(*p)){
				buffer_append(value_buffer, p, 1);
			}
			else{
				list_pop(state_stack);
				continue;
			}
		}
		
		p++;
	}
	
	while((data = list_pop(data_stack))){
        if(list_count(data_stack) ==0){
            break;
        }
        (*json->object_dealloc)(json,data,InvokeTickArg);
	}
	
	buffer_dealloc(value_buffer);
	buffer_dealloc(name_buffer);
    buffer_dealloc(base64_buffer);
	list_dealloc(data_stack);
	list_dealloc(state_stack);
    
    return data;
}