Преглед изворни кода

ncd/NCDVal: remove NCDVal_StringGetPtr() and NCDValComposedStringResource_GetPtr(), in favor of the cstring interfaces

ambrop7 пре 13 година
родитељ
комит
4de8312008
2 измењених фајлова са 0 додато и 102 уклоњено
  1. 0 60
      ncd/NCDVal.c
  2. 0 42
      ncd/NCDVal.h

+ 0 - 60
ncd/NCDVal.c

@@ -1106,19 +1106,6 @@ size_t NCDVal_StringLength (NCDValRef string)
     }
 }
 
-void NCDValComposedStringResource_GetPtr (NCDValComposedStringResource resource, size_t offset, size_t max_length, const char **out_data, size_t *out_length)
-{
-    ASSERT(max_length > 0)
-    ASSERT(out_data)
-    ASSERT(out_length)
-    
-    resource.func_getptr(resource.user, offset, out_data, out_length);
-    
-    if (*out_length > max_length) {
-        *out_length = max_length;
-    }
-}
-
 b_cstring NCDValComposedStringResource_Cstring (NCDValComposedStringResource resource, size_t offset, size_t length)
 {
     b_cstring cstr;
@@ -1130,53 +1117,6 @@ b_cstring NCDValComposedStringResource_Cstring (NCDValComposedStringResource res
     return cstr;
 }
 
-void NCDVal_StringGetPtr (NCDValRef string, size_t offset, size_t max_length, const char **out_data, size_t *out_length)
-{
-    ASSERT(NCDVal_IsString(string))
-    ASSERT(offset < NCDVal_StringLength(string))
-    ASSERT(max_length > 0)
-    ASSERT(out_data)
-    ASSERT(out_length)
-    
-    void *ptr = NCDValMem__BufAt(string.mem, string.idx);
-    
-    switch (get_internal_type(*(int *)ptr)) {
-        case STOREDSTRING_TYPE: {
-            struct NCDVal__string *str_e = ptr;
-            *out_data = str_e->data + offset;
-            *out_length = str_e->length - offset;
-        } break;
-        
-        case IDSTRING_TYPE: {
-            struct NCDVal__idstring *ids_e = ptr;
-            *out_data = NCDStringIndex_Value(ids_e->string_index, ids_e->string_id) + offset;
-            *out_length = NCDStringIndex_Length(ids_e->string_index, ids_e->string_id) - offset;
-        } break;
-        
-        case EXTERNALSTRING_TYPE: {
-            struct NCDVal__externalstring *exs_e = ptr;
-            *out_data = exs_e->data + offset;
-            *out_length = exs_e->length - offset;
-        } break;
-        
-        case COMPOSEDSTRING_TYPE: {
-            struct NCDVal__composedstring *cms_e = ptr;
-            cms_e->func_getptr(cms_e->user, cms_e->offset + offset, out_data, out_length);
-            ASSERT(*out_data)
-            ASSERT(*out_length > 0)
-        } break;
-        
-        default:
-            ASSERT(0);
-            *out_data = NULL;
-            *out_length = 0;
-    }
-    
-    if (*out_length > max_length) {
-        *out_length = max_length;
-    }
-}
-
 b_cstring NCDVal_StringCstring (NCDValRef string)
 {
     ASSERT(NCDVal_IsString(string))

+ 0 - 42
ncd/NCDVal.h

@@ -460,15 +460,6 @@ typedef struct {
     NCDRefTarget *ref_target;
 } NCDValComposedStringResource;
 
-/**
- * Like {@link NCDVal_StringGetPtr}, but directly acceses a string resource backing a
- * ComposedString. The \a offset here is from the beginning of the resource; assuming you have
- * obtained the resource from a ComposedString using {@link NCDVal_ComposedStringResource},
- * you should not access data outside of the range outside of the one defined by
- * {@link NCDVal_ComposedStringOffset} and {@link NCDVal_StringLength}.
- */
-void NCDValComposedStringResource_GetPtr (NCDValComposedStringResource resource, size_t offset, size_t max_length, const char **out_data, size_t *out_length);
-
 /**
  * Returns a cstring referencing a range within a {@link NCDValComposedStringResource}.
  * \a offset and \a length specify the range within the resource which the returned
@@ -508,39 +499,6 @@ const char * NCDVal_StringData (NCDValRef contstring);
  */
 size_t NCDVal_StringLength (NCDValRef string);
 
-/**
- * Returns a pointer into a continuous chunk of data within a String.
- * The \a offset must be lesser than the length of the string, and \a max_length
- * must be greater than zero.
- * Both \a out_data and \a out_length must be non-NULL. *\a out_data will be set to point
- * into a continuous data chunk starting at \a offset from the beginning of the string, and
- * *\a out_length will be set to the number of bytes which are available from that pointer,
- * and to no more than \a max_length.
- * 
- * It is only guaranteed that:
- * - *out_length > 0,
- * - *out_length <= max_length.
- * 
- * This means that:
- * - *out_length may be smaller than the remainder of the string,
- * - *out_length may be larger than length_of_string - offset, i.e. you may be provided
- *   bytes that are outside of this string, unless limited by max_length.
- * 
- * For clarification, the following code is provided which prints any String to standard
- * output.
- * 
- * size_t pos = 0;
- * size_t length = NCDVal_StringLength(string);
- * while (pos < length) {
- *     const char *chunk_data;
- *     size_t chunk_len;
- *     NCDVal_StringGetPtr(string, pos, length - pos, &chunk_data, &chunk_len);
- *     fwrite(chunk_data, 1, chunk_len, stdout);
- *     pos += chunk_len;
- * }
- */
-void NCDVal_StringGetPtr (NCDValRef string, size_t offset, size_t max_length, const char **out_data, size_t *out_length);
-
 /**
  * Returns a {@link b_cstring} interface to the given string value.
  * The returned cstring is valid as long as the memory object exists.