utf8.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2013 Stefano Sabatini
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifdef TEST
  21. #include <stdio.h>
  22. #include "libavutil/avstring.h"
  23. #include "libavutil/file.h"
  24. static void print_sequence(const char *p, int l, int indent)
  25. {
  26. int i;
  27. for (i = 0; i < l; i++)
  28. printf("%02X", (uint8_t)p[i]);
  29. printf("%*s", indent-l*2, "");
  30. }
  31. int main(int argc, char **argv)
  32. {
  33. int ret;
  34. char *filename = argv[1];
  35. uint8_t *file_buf;
  36. size_t file_buf_size;
  37. uint32_t code;
  38. const uint8_t *p, *endp;
  39. ret = av_file_map(filename, &file_buf, &file_buf_size, 0, NULL);
  40. if (ret < 0)
  41. return 1;
  42. p = file_buf;
  43. endp = file_buf + file_buf_size;
  44. while (p < endp) {
  45. int l, r;
  46. const uint8_t *p0 = p;
  47. code = UINT32_MAX;
  48. r = av_utf8_decode(&code, &p, endp, 0);
  49. l = (int)(p-p0);
  50. print_sequence(p0, l, 20);
  51. if (code != UINT32_MAX) {
  52. printf("%-10d 0x%-10X %-5d ", code, code, l);
  53. if (r >= 0) {
  54. if (*p0 == '\n') printf("\\n\n");
  55. else printf ("%.*s\n", l, p0);
  56. } else {
  57. printf("invalid code range\n");
  58. }
  59. } else {
  60. printf("invalid sequence\n");
  61. }
  62. }
  63. av_file_unmap(file_buf, file_buf_size);
  64. return 0;
  65. }
  66. #endif