diff options
| author | Alexey Gavrilov <rebovas@yahoo.com> | 2024-03-25 11:24:38 +0700 |
|---|---|---|
| committer | Alexey Gavrilov <rebovas@yahoo.com> | 2024-03-25 11:24:38 +0700 |
| commit | bbac386769210a8ecccba5826cfaf75d431cc2af (patch) | |
| tree | 07e5602ec7c694e2302327de54163280a342d3c1 /include/StringOperations.cpp | |
| parent | d8a708d4a2c612c348cf7c108a7c1ad683b394d8 (diff) | |
Acpi classes + string operations
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; +}; |
