Crossfire Server, Trunk
Utils.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "Utils.h"
14 #include <vector>
15 
16 bool Utils::endsWith(const std::string& str, const std::string& with) {
17  return
18  str.length() >= with.length() &&
19  str.rfind(with) == str.length() - with.length();
20 }
21 
23  std::vector<std::string> items;
24  while (list) {
25  items.push_back(list->name);
26  list = list->next;
27  }
28 
29  bool first = true;
30  for (auto a = items.rbegin(); a != items.rend(); a++) {
31  stringbuffer_append_printf(buf, "%c%s", first ? ' ' : ',', (*a).c_str());
32  first = false;
33  }
34 }
35 
36 void Utils::writeStringArray(char **items, size_t count, StringBuffer *buf) {
37  bool first = true;
38  for (size_t item = 0; item < count; item++) {
39  stringbuffer_append_printf(buf, "%c%s", first ? ' ' : ',', items[item]);
40  first = false;
41  }
42 }
disinfect.a
a
Definition: disinfect.py:13
guildoracle.list
list
Definition: guildoracle.py:87
linked_char
Definition: global.h:86
Utils.h
make_face_from_files.str
str
Definition: make_face_from_files.py:24
disinfect.count
int count
Definition: disinfect.py:7
StringBuffer
Definition: stringbuffer.c:25
item
Definition: item.py:1
Utils::endsWith
static bool endsWith(const std::string &str, const std::string &with)
Definition: Utils.cpp:16
buf
StringBuffer * buf
Definition: readable.c:1606
stringbuffer_append_printf
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Definition: stringbuffer.c:104
Utils::writeStringArray
static void writeStringArray(char **items, size_t count, StringBuffer *buf)
Definition: Utils.cpp:36
Utils::writeLinkedChar
static void writeLinkedChar(const linked_char *list, StringBuffer *buf)
Definition: Utils.cpp:22