diff options
| author | Alexey Gavrilov <90127298+rebovas@users.noreply.github.com> | 2024-03-25 11:31:02 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-25 11:31:02 +0700 |
| commit | 91b4d8fa6bed598e2969f16a7a953e293a1b7f89 (patch) | |
| tree | 86bdf89403027760ce567927ec0f1af14d0e4a79 /include/StringOperations.cpp | |
| parent | 1abc315e02a33cd62194b93898263eefd46cbfab (diff) | |
| parent | bbac386769210a8ecccba5826cfaf75d431cc2af (diff) | |
Merge pull request #4 from rebovas/acpi_classes
Implementation ACPI tables through classes
Diffstat (limited to 'include/StringOperations.cpp')
| -rw-r--r-- | include/StringOperations.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/StringOperations.cpp b/include/StringOperations.cpp new file mode 100644 index 0000000..01e7a76 --- /dev/null +++ b/include/StringOperations.cpp @@ -0,0 +1,67 @@ +#include "StringOperations.h" + + +MemArea::MemArea() +{ + start = final = NULL; +}; + +MemArea::MemArea(const memAddr start, const memAddr final) +{ + this->start = start; + this->final = final; + + if(!valid()) + { + *this = MemArea(); + } +}; + +memAddr MemArea::begin() +{ + return start; +} + +memAddr MemArea::end() +{ + if(start == final) return start; + else return final + 1; +}; + +bool MemArea::valid() +{ + if(start > final + or start == NULL + or final == NULL) return false; + else return true; +}; + +uint32 StringOperations::sequenceSize(const char *chars) +{ + uint32 indx = 0; + while(chars[indx++]){} + + return --indx; +}; + +void *StringOperations::findInMemory(const char *sequence, MemArea memory) +{ + if(sequence == nullptr or !memory.valid()) return NULL; + + uint32 seqIndx = 0; + for(MemArea::iterator it = memory.begin(); it != memory.end(); it++) + { + char ch = sequence[seqIndx], chMem = (*((char *)it)); + + if(ch == '\0') return (void *)(it - sequenceSize(sequence)); + else if(ch != chMem) + { + seqIndx = 0; + } + else if(ch == chMem) + { + seqIndx++; + } + } + return NULL; +}; |
