Browse Source

ncd: NCDValue: add NCDValue_StringHasNoNulls() and NCDValue_StringEquals()

ambrop7 14 years ago
parent
commit
52ac6871cf
2 changed files with 16 additions and 0 deletions
  1. 14 0
      ncd/NCDValue.c
  2. 2 0
      ncd/NCDValue.h

+ 14 - 0
ncd/NCDValue.c

@@ -211,6 +211,20 @@ size_t NCDValue_StringLength (NCDValue *o)
     return o->string_len;
 }
 
+int NCDValue_StringHasNoNulls (NCDValue *o)
+{
+    ASSERT(o->type == NCDVALUE_STRING)
+    
+    return strlen((char *)o->string) == o->string_len;
+}
+
+int NCDValue_StringEquals (NCDValue *o, const char *str)
+{
+    ASSERT(o->type == NCDVALUE_STRING)
+    
+    return NCDValue_StringHasNoNulls(o) && !strcmp(o->string, str);
+}
+
 void NCDValue_InitList (NCDValue *o)
 {
     LinkedList2_Init(&o->list);

+ 2 - 0
ncd/NCDValue.h

@@ -78,6 +78,8 @@ int NCDValue_InitString (NCDValue *o, const char *str) WARN_UNUSED;
 int NCDValue_InitStringBin (NCDValue *o, const uint8_t *str, size_t len) WARN_UNUSED;
 char * NCDValue_StringValue (NCDValue *o);
 size_t NCDValue_StringLength (NCDValue *o);
+int NCDValue_StringHasNoNulls (NCDValue *o);
+int NCDValue_StringEquals (NCDValue *o, const char *str);
 
 void NCDValue_InitList (NCDValue *o);
 int NCDValue_ListAppend (NCDValue *o, NCDValue v) WARN_UNUSED;