test_strings.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_STRINGS_H_
  23. #define _TEST_STRINGS_H_
  24. /* test string manipulation */
  25. void test_strings()
  26. {
  27. char* str = tsk_null;
  28. int index;
  29. /* IndexOf */
  30. index = tsk_strindexOf("C:\\test.zip", 5, "\\");
  31. index = tsk_strindexOf("C:\\test.zip", tsk_strlen("C:\\test.zip"), "abc");
  32. index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), "\\");
  33. index = tsk_strLastIndexOf("C:\\my dirctory\\test.zip", tsk_strlen("C:\\my dirctory\test.zip"), ".");
  34. /* LastIndexOf */
  35. /* concatenation */
  36. tsk_strcat(&str, " first ");
  37. printf("test_strings/// strcat=%s\n", str);
  38. /* Trim Right */
  39. tsk_strtrim_right(&str);
  40. printf("test_strings/// trim_right=%s\n", str);
  41. tsk_strcat(&str, "second");
  42. printf("test_strings/// strcat=%s\n", str);
  43. /* Trim Left */
  44. tsk_strtrim_left(&str);
  45. printf("test_strings/// trim_left=%s\n", str);
  46. tsk_free((void**)&str);
  47. /* sprintf */
  48. tsk_sprintf(&str, " \n\t%s %s\r ", "first", "second");
  49. printf("test_strings/// strcat=\"%s\"\n", str);
  50. /* Trim Both */
  51. tsk_strtrim_both(&str);
  52. printf("test_strings/// trim_both=%s\n", str);
  53. /* Quote */
  54. tsk_strquote(&str);
  55. printf("test_strings/// quote=%s\n", str);
  56. /* Unquote */
  57. tsk_strunquote(&str);
  58. printf("test_strings/// unquote=%s\n", str);
  59. tsk_free((void**)&str);
  60. }
  61. #endif /* _TEST_STRINGS_H_ */