FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utf8.c
Go to the documentation of this file.
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 
21 #include <stdio.h>
22 
23 #include "libavutil/avstring.h"
24 #include "libavutil/file.h"
25 
26 static void print_sequence(const char *p, int l, int indent)
27 {
28  int i;
29  for (i = 0; i < l; i++)
30  printf("%02X", (uint8_t)p[i]);
31  printf("%*s", indent-l*2, "");
32 }
33 
34 int main(int argc, char **argv)
35 {
36  int ret;
37  char *filename = argv[1];
38  uint8_t *file_buf;
39  size_t file_buf_size;
40  uint32_t code;
41  const uint8_t *p, *endp;
42 
43  ret = av_file_map(filename, &file_buf, &file_buf_size, 0, NULL);
44  if (ret < 0)
45  return 1;
46 
47  p = file_buf;
48  endp = file_buf + file_buf_size;
49  while (p < endp) {
50  int l, r;
51  const uint8_t *p0 = p;
52  code = UINT32_MAX;
53  r = av_utf8_decode(&code, &p, endp, 0);
54  l = (int)(p-p0);
55  print_sequence(p0, l, 20);
56  if (code != UINT32_MAX) {
57  printf("%-10d 0x%-10X %-5d ", code, code, l);
58  if (r >= 0) {
59  if (*p0 == '\n') printf("\\n\n");
60  else printf ("%.*s\n", l, p0);
61  } else {
62  printf("invalid code range\n");
63  }
64  } else {
65  printf("invalid sequence\n");
66  }
67  }
68 
69  av_file_unmap(file_buf, file_buf_size);
70  return 0;
71 }
#define NULL
Definition: coverity.c:32
int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end, unsigned int flags)
Read and decode a single UTF-8 code point (character) from the buffer in *buf, and update *buf to poi...
Definition: avstring.c:343
uint8_t
Misc file utilities.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:129
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Definition: file.c:49
const char * r
Definition: vf_curves.c:107
int main(int argc, char **argv)
Definition: utf8.c:34
static void print_sequence(const char *p, int l, int indent)
Definition: utf8.c:26