char_size.pass.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // size_type find_first_not_of(charT c, size_type pos = 0) const;
  11. #include <string>
  12. #include <cassert>
  13. template <class S>
  14. void
  15. test(const S& s, typename S::value_type c, typename S::size_type pos,
  16. typename S::size_type x)
  17. {
  18. assert(s.find_first_not_of(c, pos) == x);
  19. if (x != S::npos)
  20. assert(pos <= x && x < s.size());
  21. }
  22. template <class S>
  23. void
  24. test(const S& s, typename S::value_type c, typename S::size_type x)
  25. {
  26. assert(s.find_first_not_of(c) == x);
  27. if (x != S::npos)
  28. assert(x < s.size());
  29. }
  30. typedef std::string S;
  31. int main()
  32. {
  33. test(S(""), 'q', 0, S::npos);
  34. test(S(""), 'q', 1, S::npos);
  35. test(S("kitcj"), 'q', 0, 0);
  36. test(S("qkamf"), 'q', 1, 1);
  37. test(S("nhmko"), 'q', 2, 2);
  38. test(S("tpsaf"), 'q', 4, 4);
  39. test(S("lahfb"), 'q', 5, S::npos);
  40. test(S("irkhs"), 'q', 6, S::npos);
  41. test(S("gmfhdaipsr"), 'q', 0, 0);
  42. test(S("kantesmpgj"), 'q', 1, 1);
  43. test(S("odaftiegpm"), 'q', 5, 5);
  44. test(S("oknlrstdpi"), 'q', 9, 9);
  45. test(S("eolhfgpjqk"), 'q', 10, S::npos);
  46. test(S("pcdrofikas"), 'q', 11, S::npos);
  47. test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
  48. test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
  49. test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
  50. test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
  51. test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
  52. test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
  53. test(S(""), 'q', S::npos);
  54. test(S("csope"), 'q', 0);
  55. test(S("gfsmthlkon"), 'q', 0);
  56. test(S("laenfsbridchgotmkqpj"), 'q', 0);
  57. }