octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #34713] str2double() ignores spaces and multip


From: Kris Thielemans
Subject: [Octave-bug-tracker] [bug #34713] str2double() ignores spaces and multiple commas
Date: Wed, 21 Dec 2011 12:20:27 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1) Gecko/20100101 Firefox/8.0.1

Follow-up Comment #4, bug #34713 (project octave):

It turns out that we could let istream>> do the comma handling by setting the
local appropriatelly by simply removing the lines that remove the comma and
setting the local there the something like en_US (see code below).

With this, all current tests succeed and we also have good handling of
comma's:

octave> str2double('2,235.6 + 35,564.3i')
ans =  2.2356e+03 + 3.5564e+04i
octave> str2double('2,23,5.6')
ans = NaN

This solution is very elegant, but unfortunately has a major problem: local
naming is not set by the standard (on Ubuntu 11.10 I can use "en_US.UTF-8",
but Microsoft seems to use "english_US" (see
http://msdn.microsoft.com/en-us/library/hzz3tw78.aspx), and it's not clear if
en_US is installed on all systems in any case. I have no solution for this.

Of course, arguably str2double should use the system local anyway, but that
would seem to break matlab compatibility.

$ hg diff str2double.cc 
diff -r e5e74694c690 src/DLD-FUNCTIONS/str2double.cc
--- a/src/DLD-FUNCTIONS/str2double.cc   Wed Dec 21 09:08:10 2011 +0000
+++ b/src/DLD-FUNCTIONS/str2double.cc   Wed Dec 21 11:34:41 2011 +0000
@@ -227,13 +227,10 @@
 {
   Complex val (0.0, 0.0);
 
-  std::string str = str_arg;
+  std::istringstream is (str_arg);
+  // handle comma's
+  is.imbue( std::locale("en_US.UTF-8") );
 
-  // FIXME -- removing all commas does too much...
-  std::string::iterator se = str.end ();
-  se = std::remove (str.begin (), se, ',');
-  str.erase (se, str.end ());
-  std::istringstream is (str);
 


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?34713>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]