utf8_throw_if_error.cpp 900 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/utf8/status.h>
  5. #include<__vic/utf8/exceptions.h>
  6. #include<__vic/error.h>
  7. #include<__vic/string_buffer.h>
  8. namespace __vic { namespace utf8 {
  9. //----------------------------------------------------------------------------
  10. bool throw_if_error(status_t st)
  11. {
  12. switch(st)
  13. {
  14. case status::ok: return true;
  15. case status::eof: return false;
  16. case status::no_leading_byte: throw no_leading_byte();
  17. case status::truncated_code_point: throw truncated_code_point();
  18. case status::overlong_encoding: throw overlong_encoding();
  19. case status::code_point_too_big: throw code_point_too_big();
  20. }
  21. // Must never happen
  22. throw __vic::exception(__vic::msg(64) <<
  23. "Unexpected utf8::status value " << static_cast<int>(st));
  24. }
  25. //------------------------------------------------------------------------------
  26. }} // namespace