Author: cazfi
Date: Thu Jul 30 00:58:44 2015
New Revision: 29265

URL: http://svn.gna.org/viewcvs/freeciv?rev=29265&view=rev
Log:
Refactored get_tokens()

See patch #6143

Modified:
    trunk/utility/shared.c

Modified: trunk/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.c?rev=29265&r1=29264&r2=29265&view=diff
==============================================================================
--- trunk/utility/shared.c      (original)
+++ trunk/utility/shared.c      Thu Jul 30 00:58:44 2015
@@ -291,27 +291,19 @@
  **tokens using free_tokens().
 ***************************************************************/
 int get_tokens(const char *str, char **tokens, size_t num_tokens,
-              const char *delimiterset)
-{
-  int token = 0;
+               const char *delimiterset)
+{
+  int token;
 
   fc_assert_ret_val(NULL != str, -1);
 
-  for(;;) {
+  for (token = 0; token <= num_tokens && *str != '\0'; token++) {
     size_t len, padlength = 0;
 
     /* skip leading delimiters */
     str += strspn(str, delimiterset);
 
-    if (*str == '\0') {
-      break;
-    }
-
     len = fc_strcspn(str, delimiterset);
-
-    if (token >= num_tokens) {
-      break;
-    }
 
     /* strip start/end quotes if they exist */
     if (len >= 2) {
@@ -325,8 +317,6 @@
 
     tokens[token] = fc_malloc(len + 1);
     (void) fc_strlcpy(tokens[token], str, len + 1);     /* adds the '\0' */
-
-    token++;
 
     str += len + padlength;
   }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to