Freeciv21
Develop your civilization from humble roots to a global empire
fcintl.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <fc_config.h>
15 
16 #include <cstring>
17 
18 #include "fcintl.h"
19 
20 static bool autocap = false;
21 
39 const char *skip_intl_qualifier_prefix(const char *str)
40 {
41  const char *ptr;
42 
43  if (*str != '?') {
44  return str;
45  } else if ((ptr = strchr(str, ':'))) {
46  return (ptr + 1);
47  } else {
48  return str; // may be something wrong
49  }
50 }
51 
57 char *capitalized_string(const char *str)
58 {
59  int len = qstrlen(str);
60  char *result = new char[len + 1];
61  fc_strlcpy(result, str, len + 1);
62 
63  if (autocap) {
64  if (static_cast<unsigned char>(result[0]) < 128) {
65  result[0] = QChar::toUpper(result[0]);
66  }
67  }
68 
69  return result;
70 }
71 
75 void free_capitalized(char *str)
76 {
77  delete[] str;
78  str = nullptr;
79 }
80 
84 void capitalization_opt_in(bool opt_in) { autocap = opt_in; }
85 
90 
94 const char *get_locale_dir() { return LOCALEDIR; }
static bool autocap
Definition: fcintl.cpp:20
const char * get_locale_dir()
Return directory containing locales.
Definition: fcintl.cpp:94
char * capitalized_string(const char *str)
This function tries to capitalize first letter of the string.
Definition: fcintl.cpp:57
const char * skip_intl_qualifier_prefix(const char *str)
Some strings are ambiguous for translation.
Definition: fcintl.cpp:39
void free_capitalized(char *str)
Free capitalized string.
Definition: fcintl.cpp:75
void capitalization_opt_in(bool opt_in)
Translation opts in to automatic capitalization features.
Definition: fcintl.cpp:84
bool is_capitalization_enabled()
Automatic capitalization features requested.
Definition: fcintl.cpp:89
int len
Definition: packhand.cpp:127
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
Definition: support.cpp:412