utf8.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <stdio.h>
  21. #include "libavutil/avstring.h"
  22. #include "libavutil/file.h"
  23. static void print_sequence(const char *p, int l, int indent)
  24. {
  25. int i;
  26. for (i = 0; i < l; i++)
  27. printf("%02X", (uint8_t)p[i]);
  28. printf("%*s", indent-l*2, "");
  29. }
  30. int main(int argc, char **argv)
  31. {
  32. int ret;
  33. char *filename = argv[1];
  34. uint8_t *file_buf;
  35. size_t file_buf_size;
  36. uint32_t code;
  37. const uint8_t *p, *endp;
  38. ret = av_file_map(filename, &file_buf, &file_buf_size, 0, NULL);
  39. if (ret < 0)
  40. return 1;
  41. p = file_buf;
  42. endp = file_buf + file_buf_size;
  43. while (p < endp) {
  44. int l, r;
  45. const uint8_t *p0 = p;
  46. code = UINT32_MAX;
  47. r = av_utf8_decode(&code, &p, endp, 0);
  48. l = (int)(p-p0);
  49. print_sequence(p0, l, 20);
  50. if (code != UINT32_MAX) {
  51. printf("%-10d 0x%-10X %-5d ", code, code, l);
  52. if (r >= 0) {
  53. if (*p0 == '\n') printf("\\n\n");
  54. else printf ("%.*s\n", l, p0);
  55. } else {
  56. printf("invalid code range\n");
  57. }
  58. } else {
  59. printf("invalid sequence\n");
  60. }
  61. }
  62. av_file_unmap(file_buf, file_buf_size);
  63. return 0;
  64. }