1
0

cstrlib.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Utility library for C strings */
  2. #include <windows.h>
  3. extern "C"
  4. char *scanstr_back(char *str, char *toscan, char *defval)
  5. {
  6. char *s=str+strlen(str)-1;
  7. if (strlen(str) < 1) return defval;
  8. if (strlen(toscan) < 1) return defval;
  9. while (1)
  10. {
  11. char *t=toscan;
  12. while (*t)
  13. if (*t++ == *s) return s;
  14. t=CharPrev(str,s);
  15. if (t==s) return defval;
  16. s=t;
  17. }
  18. }
  19. extern "C"
  20. char *extension(char *fn)
  21. {
  22. char *s = scanstr_back(fn,".\\",fn-1);
  23. if (s < fn) return "";
  24. if (*s == '\\') return "";
  25. return (s+1);
  26. }
  27. void CleanDirectory(char *str)
  28. {
  29. if (!str)
  30. return;
  31. int l = strlen(str);
  32. while (l--)
  33. {
  34. if (str[l] == ' '
  35. || str[l] == '.')
  36. str[l]=0;
  37. else
  38. break;
  39. }
  40. }
  41. void FormatSizeStr64(char *out, __int64 size)
  42. {
  43. if (size < 1024*1024) wsprintf(out, "%u KB", (DWORD)(size >> 10));
  44. else if (size < 1024*1024*1024)
  45. {
  46. wsprintf(out, "%u.%02u MB", (DWORD)(size >> 20), ((((DWORD)(size >> 10))&1023)*100) >> 10);
  47. }
  48. else
  49. {
  50. wsprintf(out, "%u.%02u GB", (DWORD)(size >> 30), ((((DWORD)(size >> 20))&1023)*100) >> 10);
  51. }
  52. }