Freeciv-3.3
Loading...
Searching...
No Matches
utf8string.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19
20/* SDL2 */
21#ifdef SDL2_PLAIN_INCLUDE
22#include <SDL_types.h>
23#else /* SDL2_PLAIN_INCLUDE */
24#include <SDL2/SDL_types.h>
25#endif /* SDL2_PLAIN_INCLUDE */
26
27/* utility */
28#include "mem.h"
29
30#include "utf8string.h"
31
32/**********************************************************************/
35char **create_new_line_utf8strs(const char *pstr)
36{
37 static char *buf[512];
38 const char *start = pstr;
39 size_t len = 0, count = 0;
40
41 while (*start != '\0') {
42 if (*pstr == '\n') { /* find a new line char */
43 if (len) {
44 buf[count] = fc_calloc(len + 1, 1);
45 memcpy(buf[count], start, len);
46 } else {
47 buf[count] = fc_calloc(2, 1);
48 buf[count][0] = ' ';
49 }
50 start = pstr + 1;
51 len = 0;
52 count++;
53 } else {
54 len++;
55 }
56
57 pstr++;
58
59 if (*pstr == '\0') {
60 if (len != 0) {
61 buf[count] = fc_calloc(len + 1, 1);
62 memcpy(buf[count], start, len);
63 count++;
64 }
65
66 buf[count] = NULL;
67 start = pstr;
68 }
69 }
70
71 return buf;
72}
char * incite_cost
Definition comments.c:76
char ** create_new_line_utf8strs(const char *pstr)
Definition utf8string.c:35
#define fc_calloc(n, esz)
Definition mem.h:38
int len
Definition packhand.c:127