Freeciv-3.2
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/* utility */
21#include "mem.h"
22
23#include "utf8string.h"
24
25/**********************************************************************/
28char **create_new_line_utf8strs(const char *pstr)
29{
30 static char *buf[512];
31 const char *start = pstr;
32 size_t len = 0, count = 0;
33
34 while (*start != '\0') {
35 if (*pstr == '\n') { /* find a new line char */
36 if (len) {
37 buf[count] = fc_calloc(len + 1, 1);
38 memcpy(buf[count], start, len);
39 } else {
40 buf[count] = fc_calloc(2, 1);
41 buf[count][0] = ' ';
42 }
43 start = pstr + 1;
44 len = 0;
45 count++;
46 } else {
47 len++;
48 }
49
50 pstr++;
51
52 if (*pstr == '\0') {
53 if (len != 0) {
54 buf[count] = fc_calloc(len + 1, 1);
55 memcpy(buf[count], start, len);
56 count++;
57 }
58
59 buf[count] = NULL;
60 start = pstr;
61 }
62 }
63
64 return buf;
65}
char * incite_cost
Definition comments.c:75
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