]> Kevux Git Server - fll/commitdiff
Update: Strip out NULL characters after applying delimits.
authorKevin Day <thekevinday@gmail.com>
Wed, 13 Jul 2022 23:19:21 +0000 (18:19 -0500)
committerKevin Day <thekevinday@gmail.com>
Wed, 13 Jul 2022 23:19:21 +0000 (18:19 -0500)
Once a rule is read and the IKI data is parsed, apply the IKI delimits.
NULL characters replace the delimits.
Strip out all NULL characters from the string after the delimits are applied.

level_3/controller/c/rule/private-rule.c
level_3/controller/c/rule/private-rule.h

index 1b48e9d53d0b4c80cce74cd2204600eb1c019a2c..001668f5e70ea42d54c741d5dab9b84edef0b31f 100644 (file)
@@ -163,10 +163,14 @@ extern "C" {
             return status;
           }
 
-          // Apply the IKI delimits to the buffer.
-          for (f_array_length_t j = 0; j < action->ikis.array[action->ikis.used].delimits.used; ++j) {
-            action->parameters.array[action->parameters.used].string[action->ikis.array[action->ikis.used].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0];
-          } // for
+          // Apply the IKI delimits to the buffer, stripping out the NULL characters.
+          status = controller_rule_action_read_delimit_apply(global, &global.thread->cache, &action->ikis.array[action->ikis.used], &action->parameters.array[action->parameters.used]);
+
+          if (F_status_is_error(status)) {
+            controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true);
+
+            return status;
+          }
         }
 
         ++action->parameters.used;
@@ -317,10 +321,14 @@ extern "C" {
               return status;
             }
 
-            // Apply the IKI delimits to the buffer.
-            for (f_array_length_t j = 0; j < actions->array[actions->used].ikis.array[0].delimits.used; ++j) {
-              actions->array[actions->used].parameters.array[0].string[actions->array[actions->used].ikis.array[0].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0];
-            } // for
+            // Apply the IKI delimits to the buffer, stripping out the NULL characters.
+            status = controller_rule_action_read_delimit_apply(global, cache, &actions->array[actions->used].ikis.array[0], &actions->array[actions->used].parameters.array[0]);
+
+            if (F_status_is_error(status)) {
+              controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true);
+
+              return status;
+            }
           }
 
           actions->array[actions->used].ikis.used = 1;
@@ -632,10 +640,14 @@ extern "C" {
               return status;
             }
 
-            // Apply the IKI delimits to the buffer.
-            for (f_array_length_t j = 0; j < actions->array[actions->used].ikis.array[0].delimits.used; ++j) {
-              actions->array[actions->used].parameters.array[0].string[actions->array[actions->used].ikis.array[0].delimits.array[j]] = f_iki_syntax_placeholder_s.string[0];
-            } // for
+            // Apply the IKI delimits to the buffer, stripping out the NULL characters.
+            status = controller_rule_action_read_delimit_apply(global, cache, &actions->array[actions->used].ikis.array[0], &actions->array[actions->used].parameters.array[0]);
+
+            if (F_status_is_error(status)) {
+              controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_action_read_delimit_apply", F_true);
+
+              return status;
+            }
           }
 
           actions->array[actions->used].ikis.used = 1;
@@ -686,6 +698,32 @@ extern "C" {
   }
 #endif // _di_controller_rule_action_read_
 
+#ifndef _di_controller_rule_action_read_delimit_apply_
+  f_status_t controller_rule_action_read_delimit_apply(const controller_global_t global, controller_cache_t * const cache, f_iki_data_t * const iki_data, f_string_dynamic_t * const destination) {
+
+    if (!iki_data->delimits.used) return F_none;
+
+    cache->expanded.used = 0;
+
+    f_status_t status = f_string_dynamics_increase(F_memory_default_allocation_small_d, &cache->expanded);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_append(*destination, &cache->expanded.array[0]);
+    if (F_status_is_error(status)) return status;
+
+    for (f_array_length_t j = 0; j < iki_data->delimits.used; ++j) {
+      cache->expanded.array[0].string[iki_data->delimits.array[j]] = f_iki_syntax_placeholder_s.string[0];
+    } // for
+
+    destination->used = 0;
+
+    status = f_string_dynamic_append_nulless(cache->expanded.array[0], destination);
+    if (F_status_is_error(status)) return status;
+
+    return F_none;
+  }
+#endif // _di_controller_rule_action_read_delimit_apply_
+
 #ifndef _di_controller_rule_action_read_rerun_number_
   f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t * const index, f_number_unsigned_t * const number) {
 
index 6af56659757c0cc5c78d1f82524142a74247fe10..b9f6af7f5315928a9c6c50efbe8851295eeb0c60 100644 (file)
@@ -159,6 +159,34 @@ extern "C" {
 #endif // _di_controller_rule_action_read_
 
 /**
+ * Apply delimits and remove resulting NULL characters.
+ *
+ * @param global
+ *   The global data.
+ * @param cache
+ *   A structure for containing and caching relevant data.
+ *   This uses cache->expanded.
+ * @param iki_data
+ *   The IKI data to process.
+ * @param destination
+ *   The string to save the expanded data to.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   Errors (with error bit) from: f_string_dynamic_append().
+ *   Errors (with error bit) from: f_string_dynamic_append_nulless().
+ *   Errors (with error bit) from: f_string_dynamics_increase().
+ *
+ * @see f_string_dynamic_append()
+ * @see f_string_dynamic_append_nulless()
+ * @see f_string_dynamics_increase()
+ */
+#ifndef _di_controller_rule_action_read_delimit_apply_
+  extern f_status_t controller_rule_action_read_delimit_apply(const controller_global_t global, controller_cache_t * const cache, f_iki_data_t * const iki_data, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
+#endif // _di_controller_rule_action_read_delimit_apply_
+
+/**
  * Copy a rule, allocating new space as necessary.
  *
  * This does not do any locking or unlocking for the rule data, be sure to lock appropriately before and after calling this.