Bläddra i källkod

misc/string_begins_with.h: add data_begins_with_bin()

ambrop7 13 år sedan
förälder
incheckning
04be86717d
1 ändrade filer med 24 tillägg och 0 borttagningar
  1. 24 0
      misc/string_begins_with.h

+ 24 - 0
misc/string_begins_with.h

@@ -69,4 +69,28 @@ static size_t string_begins_with (const char *str, const char *needle)
     return data_begins_with(str, strlen(str), needle);
 }
 
+static size_t data_begins_with_bin (const char *str, size_t str_len, const char *needle, size_t needle_len)
+{
+    ASSERT(needle_len > 0)
+    
+    size_t len = 0;
+    
+    while (str_len > 0 && needle_len > 0) {
+        if (*str != *needle) {
+            return 0;
+        }
+        str++;
+        str_len--;
+        needle++;
+        needle_len--;
+        len++;
+    }
+    
+    if (needle_len > 0) {
+        return 0;
+    }
+    
+    return len;
+}
+
 #endif