فهرست منبع

ncd: NCDVal: implement NCDValStringResource_GetPtr

ambrop7 13 سال پیش
والد
کامیت
34ff49a04d
2فایلهای تغییر یافته به همراه22 افزوده شده و 0 حذف شده
  1. 13 0
      ncd/NCDVal.c
  2. 9 0
      ncd/NCDVal.h

+ 13 - 0
ncd/NCDVal.c

@@ -1046,6 +1046,19 @@ size_t NCDVal_StringLength (NCDValRef string)
     }
 }
 
+void NCDValStringResource_GetPtr (NCDValStringResource 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;
+    }
+}
+
 void NCDVal_StringGetPtr (NCDValRef string, size_t offset, size_t max_length, const char **out_data, size_t *out_length)
 {
     ASSERT(NCDVal_IsString(string))

+ 9 - 0
ncd/NCDVal.h

@@ -446,6 +446,15 @@ typedef struct {
     NCDRefTarget *ref_target;
 } NCDValStringResource;
 
+/**
+ * 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 NCDValStringResource_GetPtr (NCDValStringResource resource, size_t offset, size_t max_length, const char **out_data, size_t *out_length);
+
 /**
  * Builds a new ComposedString from a string resource.
  * A reference to the underlying string resource via the {@link NCDRefTarget} object