2
0

strings.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "StringUtils.h"
  2. #include "Assert.h"
  3. #include <stdio.h>
  4. using namespace crown;
  5. const char* hello_string = "/h.ello.everybody.stri/ng";
  6. const char* path_string = "/home/project/texture.tga";
  7. int main()
  8. {
  9. // Test strlen
  10. CE_ASSERT(string::strlen("ciao") == 4, "");
  11. // FIXME add UTF-8 test case
  12. // Test begin/end
  13. CE_ASSERT(string::begin(hello_string) == &hello_string[0], "");
  14. CE_ASSERT(string::end(hello_string) == &hello_string[24] + 2, "");
  15. // Test find_first/find_last
  16. CE_ASSERT(string::find_first(hello_string, '.') == &hello_string[2], "");
  17. CE_ASSERT(string::find_last(hello_string, '.') == &hello_string[17], "");
  18. CE_ASSERT(string::find_first(hello_string, '?') == string::end(hello_string), "");
  19. CE_ASSERT(string::find_last(hello_string, '?') == string::end(hello_string), "");
  20. CE_ASSERT(string::find_last(hello_string, '/') == &hello_string[22], "");
  21. CE_ASSERT(string::find_last(path_string, '/') == &path_string[13], "");
  22. // Test substring
  23. char string_buffer[64];
  24. memset(string_buffer, 'a', 64);
  25. string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 64);
  26. CE_ASSERT(string::strcmp(hello_string, string_buffer) == 0, "");
  27. memset(string_buffer, 'a', 64);
  28. string::substring(string::begin(hello_string), &hello_string[11], string_buffer, 64);
  29. CE_ASSERT(string::strcmp(string_buffer, "/h.ello.eve") == 0, "");
  30. memset(string_buffer, 'a', 64);
  31. string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 5);
  32. CE_ASSERT(string::strcmp(string_buffer, "/h.el") == 0, "");
  33. }