Skip to content

Instantly share code, notes, and snippets.

@Platin21
Created November 15, 2017 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Platin21/271f1889229fd40ad79f01c601b907d1 to your computer and use it in GitHub Desktop.
Save Platin21/271f1889229fd40ad79f01c601b907d1 to your computer and use it in GitHub Desktop.
Tried to build an Abstraction around files is only a pattern not more.
#ifdef __CHAR_UNSIGNED__
using UChar = unsigned char;
#else
using UChar = char;
#endif
using i64 = long long;
i64 CStrLenghtOf(UChar* text)
{
i64 i = 0;
while(*text){ text += 1; i += 1; }
return i;
}
struct UStr
{
UChar* text;
i64 bytelenght;
UStr(const char* txt)
: text((UChar*)txt),
bytelenght(CStrLenghtOf((UChar*)txt)) {};
UStr(UChar* text,i64 withLenght)
: text((UChar*) text),
bytelenght(withLenght) {};
UStr()
: text( (UChar*)""),
bytelenght(1) {};
};
bool reverseFind(UChar charackter,UStr& inUstr)
{
i64 len = inUstr.bytelenght;
UChar* stringEnd = inUstr.text + inUstr.bytelenght;
while(*stringEnd != charackter)
{
stringEnd -= 1;
len -= 1;
if(len == 0) return false;
}
return true;
}
bool reverseFind(UChar charackter,UChar beforeThisCharackter,UStr& inUstr)
{
i64 len = inUstr.bytelenght;
UChar* stringEnd = inUstr.text + inUstr.bytelenght;
while(*stringEnd != charackter && *stringEnd != beforeThisCharackter)
{
stringEnd -= 1;
len -= 1;
if(len == 0) return false;
}
return true;
}
struct Path
{
UStr filePath;
bool valid;
Path(UStr ustr)
{
filePath = ustr;
}
};
class File
{
private:
int handle;
public:
void open(UStr Path)
{
if(*(Path.text+Path.bytelenght) != '/')
{
if(reverseFind('.','/',Path))
{
handle = 3;
}
}
};
void close()
{
handle = 0;
};
};
int main()
{
File f = {};
f.open("/test/version/hallo.txt");
f.close();
}
@Platin21
Copy link
Author

Platin21 commented Dec 1, 2018

So much stuff wich i wouldn't use anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment