Forráskód Böngészése

ncd/NCDVal: add NCDVal_HasOnlyContinuousStrings()

ambrop7 13 éve
szülő
commit
398887a489
2 módosított fájl, 50 hozzáadás és 0 törlés
  1. 41 0
      ncd/NCDVal.c
  2. 9 0
      ncd/NCDVal.h

+ 41 - 0
ncd/NCDVal.c

@@ -765,6 +765,47 @@ NCDValRef NCDVal_Moved (NCDValMem *mem, NCDValRef val)
     return val2;
 }
 
+int NCDVal_HasOnlyContinuousStrings (NCDValRef val)
+{
+    NCDVal__AssertVal(val);
+    
+    switch (NCDVal_Type(val)) {
+        case NCDVAL_STRING: {
+            if (!NCDVal_IsContinuousString(val)) {
+                return 0;
+            }
+        } break;
+        
+        case NCDVAL_LIST: {
+            size_t count = NCDVal_ListCount(val);
+            for (size_t i = 0; i < count; i++) {
+                NCDValRef elem = NCDVal_ListGet(val, i);
+                if (!NCDVal_HasOnlyContinuousStrings(elem)) {
+                    return 0;
+                }
+            }
+        } break;
+        
+        case NCDVAL_MAP: {
+            for (NCDValMapElem me = NCDVal_MapFirst(val); !NCDVal_MapElemInvalid(me); me = NCDVal_MapNext(val, me)) {
+                NCDValRef e_key = NCDVal_MapElemKey(val, me);
+                NCDValRef e_val = NCDVal_MapElemVal(val, me);
+                if (!NCDVal_HasOnlyContinuousStrings(e_key) || !NCDVal_HasOnlyContinuousStrings(e_val)) {
+                    return 0;
+                }
+            }
+        } break;
+        
+        case NCDVAL_PLACEHOLDER: {
+        } break;
+        
+        default:
+            ASSERT(0);
+    }
+    
+    return 1;
+}
+
 int NCDVal_IsString (NCDValRef val)
 {
     NCDVal__AssertVal(val);

+ 9 - 0
ncd/NCDVal.h

@@ -330,6 +330,15 @@ NCDValRef NCDVal_FromSafe (NCDValMem *mem, NCDValSafeRef sval);
  */
 NCDValRef NCDVal_Moved (NCDValMem *mem, NCDValRef val);
 
+/**
+ * Determines if all strings within this value are ContinuousString's,
+ * by recusively walking the entire value.
+ * If all strings are ContinuousString's, returns 1; if there is at least
+ * one string which is not a ContinuousString, returns 0.
+ * The value reference must not be an invalid reference.
+ */
+int NCDVal_HasOnlyContinuousStrings (NCDValRef val);
+
 /**
  * Determines if the value implements the String interface.
  * The value reference must not be an invalid reference.