Browse Source

Removed unused getFileFromFullPath()

Thomas Buck 10 years ago
parent
commit
8c4705ae16
2 changed files with 22 additions and 68 deletions
  1. 8
    15
      include/utils/strings.h
  2. 14
    53
      src/utils/strings.cpp

+ 8
- 15
include/utils/strings.h View File

@@ -3,11 +3,19 @@
3 3
  * \brief String handling utilities
4 4
  *
5 5
  * \author xythobuz
6
+ * \author Mongoose
6 7
  */
7 8
 
8 9
 #ifndef _UTILS_STRINGS_H_
9 10
 #define _UTILS_STRINGS_H_
10 11
 
12
+/*!
13
+ * \brief Check if a string ends with another string.
14
+ * \param str string to check
15
+ * \param suffix suffix for which to check
16
+ * \returns true if str ends with suffix
17
+ */
18
+bool stringEndsWith(const char *str, const char *suffix);
11 19
 
12 20
 /*!
13 21
  * \brief Generates a buffered string for the printf call
@@ -26,21 +34,6 @@ char *bufferString(const char *string, ...) __attribute__((format(printf, 1, 2))
26 34
 char *fullPath(const char *path, char end);
27 35
 
28 36
 /*!
29
- * \brief Only returns last part of a path string.
30
- * \param filename Path to a file
31
- * \returns Name of the file in filename, without path in front
32
- */
33
-char *getFileFromFullPath(char *filename);
34
-
35
-/*!
36
- * \brief Check if a string ends with another string.
37
- * \param str string to check
38
- * \param suffix suffix for which to check
39
- * \returns true if str ends with suffix
40
- */
41
-bool stringEndsWith(const char *str, const char *suffix);
42
-
43
-/*!
44 37
  * \brief Checks if Command matches Symbol.
45 38
  * Returns the rest of the argument list back in command buffer, if any
46 39
  * \param symbol command string

+ 14
- 53
src/utils/strings.cpp View File

@@ -3,6 +3,7 @@
3 3
  * \brief String handling utilities
4 4
  *
5 5
  * \author xythobuz
6
+ * \author Mongoose
6 7
  */
7 8
 
8 9
 #include <cstdarg>
@@ -59,7 +60,6 @@ char *bufferString(const char *string, ...) {
59 60
     return text;
60 61
 }
61 62
 
62
-
63 63
 char *fullPath(const char *path, char end) {
64 64
     unsigned int lenPath, offset;
65 65
     wordexp_t word;
@@ -94,7 +94,10 @@ char *fullPath(const char *path, char end) {
94 94
 
95 95
         wordfree(&word);
96 96
 #else
97
-#error Platform not supported!
97
+        printf("WARNING: Tilde expansion not supported on this platform!\n");
98
+        lenPath = strlen(path);
99
+        dir = new char[lenPath + 2]; // space for end char
100
+        strncpy(dir, path, lenPath);
98 101
 #endif
99 102
     } else {
100 103
         lenPath = strlen(path);
@@ -113,56 +116,18 @@ char *fullPath(const char *path, char end) {
113 116
     return dir;
114 117
 }
115 118
 
116
-
117
-char *getFileFromFullPath(char *filename)
118
-{
119
-    int i, j, len;
120
-    char *str;
121
-
122
-
123
-    len = strlen(filename);
124
-
125
-    for (i = len, j = 0; i > 0; --i, ++j)
126
-    {
127
-        if (filename[i] == '/' || filename[i] == '\\')
128
-            break;
129
-    }
130
-
131
-    j--;
132
-
133
-    str = new char[len - j + 1];
134
-
135
-    for (i = 0; i < len - j; ++i)
136
-    {
137
-        str[i] = filename[i + len - j];
138
-    }
139
-
140
-    str[i] = 0;
141
-
142
-    return str;
143
-}
144
-
145
-// Mongoose 2002.03.23, Checks command to see if it's same
146
-//   as symbol, then returns the arg list in command buffer
147
-bool rc_command(const char *symbol, char *command)
148
-{
149
-    int i, j, lens, lenc;
150
-
151
-
119
+bool rc_command(const char *symbol, char *command) {
152 120
     if (!symbol || !symbol[0] || !command || !command[0])
153
-    {
154 121
         return false;
155
-    }
156 122
 
157
-    lens = strlen(symbol);
123
+    int lens = strlen(symbol);
158 124
 
159
-    if (strncmp(command, symbol, lens) == 0)
160
-    {
161
-        lenc = strlen(command);
125
+    if (strncmp(command, symbol, lens) == 0) {
126
+        int lenc = strlen(command);
162 127
 
128
+        //! \fixme Should ignore whitespace, but only if it is really there...?
163 129
         // lens+1 skips '=' or ' '
164
-        for (i = 0, j = lens+1; j < lenc; ++i, ++j)
165
-        {
130
+        for (int i = 0, j = lens+1; j < lenc; ++i, ++j) {
166 131
             command[i] = command[j];
167 132
             command[i+1] = 0;
168 133
         }
@@ -173,17 +138,13 @@ bool rc_command(const char *symbol, char *command)
173 138
     return false;
174 139
 }
175 140
 
176
-
177
-int rc_get_bool(char *buffer, bool *val)
178
-{
141
+int rc_get_bool(char *buffer, bool *val) {
179 142
     if (!buffer || !buffer[0])
180
-    {
181 143
         return -1;
182
-    }
183 144
 
184
-    if ((strncmp(buffer, "true", 4) == 0) || (buffer[0] == '1'))
145
+    if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
185 146
         *val = true;
186
-    else if ((strncmp(buffer, "false", 5) == 0) || (buffer[0] == '0'))
147
+    else if ((buffer[0] == '0') || (strncmp(buffer, "false", 5) == 0))
187 148
         *val = false;
188 149
     else
189 150
         return -2;

Loading…
Cancel
Save