From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/nu/cstrlib.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Src/nu/cstrlib.cpp (limited to 'Src/nu/cstrlib.cpp') diff --git a/Src/nu/cstrlib.cpp b/Src/nu/cstrlib.cpp new file mode 100644 index 00000000..be23972a --- /dev/null +++ b/Src/nu/cstrlib.cpp @@ -0,0 +1,59 @@ +/* Utility library for C strings */ + +#include + +extern "C" +char *scanstr_back(char *str, char *toscan, char *defval) +{ + char *s=str+strlen(str)-1; + if (strlen(str) < 1) return defval; + if (strlen(toscan) < 1) return defval; + while (1) + { + char *t=toscan; + while (*t) + if (*t++ == *s) return s; + t=CharPrev(str,s); + if (t==s) return defval; + s=t; + } +} + +extern "C" +char *extension(char *fn) +{ + char *s = scanstr_back(fn,".\\",fn-1); + if (s < fn) return ""; + if (*s == '\\') return ""; + return (s+1); +} + +void CleanDirectory(char *str) +{ + if (!str) + return; + int l = strlen(str); + + while (l--) + { + if (str[l] == ' ' + || str[l] == '.') + str[l]=0; + else + break; + } +} + + +void FormatSizeStr64(char *out, __int64 size) +{ + if (size < 1024*1024) wsprintf(out, "%u KB", (DWORD)(size >> 10)); + else if (size < 1024*1024*1024) + { + wsprintf(out, "%u.%02u MB", (DWORD)(size >> 20), ((((DWORD)(size >> 10))&1023)*100) >> 10); + } + else + { + wsprintf(out, "%u.%02u GB", (DWORD)(size >> 30), ((((DWORD)(size >> 20))&1023)*100) >> 10); + } +} \ No newline at end of file -- cgit