/
usr
/
share
/
doc
/
libidn-devel
/
examples
/
/usr/share/doc/libidn-devel/examples
mkdir
upload
Name
Size
Mode
Actions
example.c
2444
0644
edit
dl
rm
example2.c
6435
0644
edit
dl
rm
example3.c
2322
0644
edit
dl
rm
example4.c
2333
0644
edit
dl
rm
example5.c
3279
0644
edit
dl
rm
Makefile.am
1003
0644
edit
dl
rm
Makefile.in
57838
0644
edit
dl
rm
README
1150
0644
edit
dl
rm
Edit:
/usr/share/doc/libidn-devel/examples/example.c
(2444B)
/* example.c --- Example code showing how to use stringprep(). * Copyright (C) 2002-2016 Simon Josefsson * * This file is part of GNU Libidn. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <locale.h> /* setlocale() */ #include <stringprep.h> /* * Compiling using libtool and pkg-config is recommended: * * $ libtool cc -o example example.c `pkg-config --cflags --libs libidn` * $ ./example * Input string encoded as `ISO-8859-1': ยช * Before locale2utf8 (length 2): aa 0a * Before stringprep (length 3): c2 aa 0a * After stringprep (length 2): 61 0a * $ * */ int main (void) { char buf[BUFSIZ]; char *p; int rc; size_t i; setlocale (LC_ALL, ""); printf ("Input string encoded as `%s': ", stringprep_locale_charset ()); fflush (stdout); if (!fgets (buf, BUFSIZ, stdin)) perror ("fgets"); buf[strlen (buf) - 1] = '\0'; printf ("Before locale2utf8 (length %ld): ", (long int) strlen (buf)); for (i = 0; i < strlen (buf); i++) printf ("%02x ", (unsigned) buf[i] & 0xFF); printf ("\n"); p = stringprep_locale_to_utf8 (buf); if (p) { strcpy (buf, p); free (p); } else printf ("Could not convert string to UTF-8, continuing anyway...\n"); printf ("Before stringprep (length %ld): ", (long int) strlen (buf)); for (i = 0; i < strlen (buf); i++) printf ("%02x ", (unsigned) buf[i] & 0xFF); printf ("\n"); rc = stringprep (buf, BUFSIZ, 0, stringprep_nameprep); if (rc != STRINGPREP_OK) printf ("Stringprep failed (%d): %s\n", rc, stringprep_strerror (rc)); else { printf ("After stringprep (length %ld): ", (long int) strlen (buf)); for (i = 0; i < strlen (buf); i++) printf ("%02x ", (unsigned) buf[i] & 0xFF); printf ("\n"); } return 0; }
Save
cmd:
run