[ekiga/gnome-2-26] Fixed #574998 (don't use strtok)



commit 90d1eb56cd8442e4b31241ebbc62b940ce96d81c
Author: Julien Puydt <jpuydt src gnome org>
Date:   Tue Mar 17 20:28:22 2009 +0000

    Fixed #574998 (don't use strtok)
    
    svn path=/trunk/; revision=7780
---
 lib/engine/protocol/codec-description.cpp |   40 ++++++++++++++++------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/lib/engine/protocol/codec-description.cpp b/lib/engine/protocol/codec-description.cpp
index fe06972..108536d 100644
--- a/lib/engine/protocol/codec-description.cpp
+++ b/lib/engine/protocol/codec-description.cpp
@@ -56,17 +56,22 @@ CodecDescription::CodecDescription (std::string _name,
                                     bool _active)
   : name (_name), rate (_rate), active (_active), audio (_audio)
 {
-  char *pch = NULL;
+  gchar** prots = NULL;
 
-  pch = strtok ((char *) _protocols.c_str (), ",");
-  while (pch != NULL) {
+  prots = g_strsplit (_protocols.c_str (), ", ", -1);
 
-    std::string protocol = pch;
-    protocol = protocol.substr (protocol.find_first_not_of (" "));
-    protocols.push_back (protocol);
-    pch = strtok (NULL, ",");
+  for (gchar** ptr = prots;
+       *ptr != NULL;
+       ptr++) {
+
+    if ((*ptr)[0] != '\0') { // not the empty string
+
+      protocols.push_back (*ptr);
+    }
   }
 
+  g_strfreev (prots);
+
   protocols.unique ();
   protocols.sort ();
 }
@@ -75,29 +80,30 @@ CodecDescription::CodecDescription (std::string _name,
 CodecDescription::CodecDescription (std::string codec)
 {
   int i = 0;
-  char *pch = NULL;
-
+  gchar** vect = NULL;
   std::string tmp [5];
 
-  pch = strtok ((char *) codec.c_str (), "*");
-  while (pch != NULL) {
+  vect = g_strsplit (codec.c_str (), "*", -1);
 
-    tmp [i] = pch;
-    pch = strtok (NULL, "*");
+  for (gchar** ptr = vect; *ptr != NULL; ptr++) {
 
+    tmp[i] = *ptr;
     i++;
   }
 
+  g_strfreev (vect);
+
   if (i < 4)
     return;
 
-  pch = strtok ((char *) tmp [3].c_str (), " ");
-  while (pch != NULL) {
+  vect = g_strsplit (tmp[3].c_str (), " ", -1);
+  for (gchar** ptr = vect; *ptr != NULL; ptr++) {
 
-    protocols.push_back (pch);
-    pch = strtok (NULL, " ");
+    protocols.push_back (*ptr);
   }
 
+  g_strfreev (vect);
+
   name = tmp [0];
   rate = atoi (tmp [1].c_str ());
   audio = atoi (tmp [2].c_str ());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]