#ifndef PROTOTYPE1_SRC_L1_5_CORE_STRINGOP_H
#define PROTOTYPE1_SRC_L1_5_CORE_STRINGOP_H

#include "../../../gen/l1/VecAndSpan_U8.h"
#include "../../../gen/l1/VecAndSpan_VecU8.h"
#include "../../../gen/l1/VecAndSpan_SpanU8.h"
#include "../../l1/core/VecU8_as_str.h"

U8 U8_to_lowercase(U8 ch) {
    if ('A' <= ch && ch <= 'Z')
        return ch - 'A' + 'a';
    return ch;
}

// Worst case time complexity: O(nm)
bool string_contains_string_ignorecase(SpanU8 str1, SpanU8 str2) {
    size_t L = str2.len;
    for (size_t i = 0; i + L <= str1.len; i++) {
        for (size_t j = 0; j < L; j++) {
            if (U8_to_lowercase(*SpanU8_at(str1, i + j)) != U8_to_lowercase(*SpanU8_at(str2, j)))
                goto e;
        }
        return true;
        e:
        int u;
    }
    return false;
}

bool is_string_in_string_vec(SpanU8 a, const VecVecU8* B) {
    for (size_t i = 0; i < B->len; i++) {
        if (strings_in_spans_equal(a, VecU8_to_span(VecVecU8_at(B, i))))
            return true;
    }
    return false;
}

void VecU8_add_vertical_separator(VecU8* self) {
    if (self->len)
        VecU8_append_span(self, cstr(" | "));
}

#endif
