digitalmars.D.learn - sscanf() equivalent for D using Phobos library?
- rocknroll714 (12/12) Dec 03 2008 Hi. I discovered D recently and I am very, very impressed. I've
- Jarrett Billingsley (2/14) Dec 03 2008 import std.cstream;, and use din.readf. readf is documented in std.stre...
- Spacen Jasset (2/23) Dec 04 2008 This seems to work on a file, but can this be done on a char[] ?
- Steven Schveighoffer (5/30) Dec 04 2008 might be talking out of my ass, since I'm a tango user, but I think read...
- Bill Baxter (9/38) Dec 04 2008 I think that's what std.stream.MemoryStream is for, but I might be
- BCS (2/9) Dec 04 2008 One new MemoeryStream per line!?!?
- Bill Baxter (13/23) Dec 04 2008 It's scope! No worries mate! ;-)
- BCS (2/29) Dec 04 2008 there should so be a std.scan.scan function to go with the std.format.fo...
- Jarrett Billingsley (4/15) Dec 04 2008 I could never quite figure out why Stream.readf was not separated out
-
BCS
(2/21)
Dec 04 2008
do it, submit patch, become hero.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/7) Dec 05 2008 I thought that was what std.unformat was for ?
- Jarrett Billingsley (4/11) Dec 05 2008 Such a library exists? It's not in the D docs. I don't see anything
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (3/10) Dec 05 2008 It was suggested for DMD 0.128, but I don't think it made it.
- BCS (5/22) Dec 03 2008 the quick and wrong way that works is to go find std.c.stdio and call th...
Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!
Dec 03 2008
On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!import std.cstream;, and use din.readf. readf is documented in std.stream. :)
Dec 03 2008
Jarrett Billingsley wrote:On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:This seems to work on a file, but can this be done on a char[] ?Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!import std.cstream;, and use din.readf. readf is documented in std.stream. :)
Dec 04 2008
"Spacen Jasset" wroteJarrett Billingsley wrote:might be talking out of my ass, since I'm a tango user, but I think readf is a function used by all streams? So you just need to make that char[] into a stream, and then you get readf functionality, maybe. -SteveOn Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:This seems to work on a file, but can this be done on a char[] ?Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!import std.cstream;, and use din.readf. readf is documented in std.stream. :)
Dec 04 2008
On Fri, Dec 5, 2008 at 9:06 AM, Steven Schveighoffer <schveiguy yahoo.com> wrote:"Spacen Jasset" wroteI think that's what std.stream.MemoryStream is for, but I might be talking out of my ass too because I've never used it. But it looks like you could say scope thestream = new std.stream.MemoryStream(thebuffer); then use thestream just like it was a file. You may have to cast(byte[])thebuffer, though. --bbJarrett Billingsley wrote:might be talking out of my ass, since I'm a tango user, but I think readf is a function used by all streams? So you just need to make that char[] into a stream, and then you get readf functionality, maybe.On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:This seems to work on a file, but can this be done on a char[] ?Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!import std.cstream;, and use din.readf. readf is documented in std.stream. :)
Dec 04 2008
Reply to Bill,One new MemoeryStream per line!?!?scope thestream = new std.stream.MemoryStream(thebuffer);On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:I'm looping through a text file using the File.getline() command
Dec 04 2008
On Fri, Dec 5, 2008 at 11:09 AM, BCS <ao pathlink.com> wrote:Reply to Bill,It's scope! No worries mate! ;-) But seriously, it does sound heavyweight compared to a single sscanf function call. Honestly, std.stream is just barely functional enough to write the simplest stream code, so I wouldn't be surprised if that's what it takes to scan strings with it. Not much worse than what it takes to do it with std::stream in c++ though. I'm really talking out of my ass though, because I can probably count on one hand how many times written code to use scanf or stringstream in my life. If I have to parse input I'm much more likely to reach for the regexp hammer or write a simpler parser. --bbOne new MemoeryStream per line!?!?scope thestream = new std.stream.MemoryStream(thebuffer);On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:I'm looping through a text file using the File.getline() command
Dec 04 2008
Reply to Bill,On Fri, Dec 5, 2008 at 11:09 AM, BCS <ao pathlink.com> wrote:there should so be a std.scan.scan function to go with the std.format.format.Reply to Bill,It's scope! No worries mate! ;-) But seriously, it does sound heavyweight compared to a single sscanf function call. Honestly, std.stream is just barely functional enough to write the simplest stream code, so I wouldn't be surprised if that's what it takes to scan strings with it. Not much worse than what it takes to do it with std::stream in c++ though. I'm really talking out of my ass though, because I can probably count on one hand how many times written code to use scanf or stringstream in my life. If I have to parse input I'm much more likely to reach for the regexp hammer or write a simpler parser. --bbOne new MemoeryStream per line!?!?scope thestream = new std.stream.MemoryStream(thebuffer);On Wed, Dec 3, 2008 at 6:37 PM, rocknroll714 <rocknroll714 gmail.com> wrote:I'm looping through a text file using the File.getline() command
Dec 04 2008
On Thu, Dec 4, 2008 at 9:25 PM, Bill Baxter <wbaxter gmail.com> wrote:It's scope! No worries mate! ;-) But seriously, it does sound heavyweight compared to a single sscanf function call. Honestly, std.stream is just barely functional enough to write the simplest stream code, so I wouldn't be surprised if that's what it takes to scan strings with it. Not much worse than what it takes to do it with std::stream in c++ though. I'm really talking out of my ass though, because I can probably count on one hand how many times written code to use scanf or stringstream in my life. If I have to parse input I'm much more likely to reach for the regexp hammer or write a simpler parser.I could never quite figure out why Stream.readf was not separated out into a separate function in std.format. It probably wouldn't be a lot of work.
Dec 04 2008
Reply to Jarrett,On Thu, Dec 4, 2008 at 9:25 PM, Bill Baxter <wbaxter gmail.com> wrote:do it, submit patch, become hero. <G>It's scope! No worries mate! ;-) But seriously, it does sound heavyweight compared to a single sscanf function call. Honestly, std.stream is just barely functional enough to write the simplest stream code, so I wouldn't be surprised if that's what it takes to scan strings with it. Not much worse than what it takes to do it with std::stream in c++ though. I'm really talking out of my ass though, because I can probably count on one hand how many times written code to use scanf or stringstream in my life. If I have to parse input I'm much more likely to reach for the regexp hammer or write a simpler parser.I could never quite figure out why Stream.readf was not separated out into a separate function in std.format. It probably wouldn't be a lot of work.
Dec 04 2008
Jarrett Billingsley wrote:I could never quite figure out why Stream.readf was not separated out into a separate function in std.format. It probably wouldn't be a lot of work.I thought that was what std.unformat was for ? But I would have put readf in std.stdio too... --anders
Dec 05 2008
On Fri, Dec 5, 2008 at 5:43 AM, Anders F Bj=F6rklund <afb algonet.se> wrote= :Jarrett Billingsley wrote:Such a library exists? It's not in the D docs. I don't see anything in the Phobos source dir either.I could never quite figure out why Stream.readf was not separated out into a separate function in std.format. It probably wouldn't be a lot of work.I thought that was what std.unformat was for ?But I would have put readf in std.stdio too... --anders
Dec 05 2008
Jarrett Billingsley wrote:It was suggested for DMD 0.128, but I don't think it made it. --andersSuch a library exists? It's not in the D docs. I don't see anything in the Phobos source dir either.I could never quite figure out why Stream.readf was not separated out into a separate function in std.format. It probably wouldn't be a lot of work.I thought that was what std.unformat was for ?
Dec 05 2008
Reply to rocknroll714,Hi. I discovered D recently and I am very, very impressed. I've decided to switch from C/C++ over to D as my programming language of choice. Right now I'm porting one of my C++ applications to D, and I need some help with a simple conversion. How would I do this: if(sscanf(line, "%[^:]: %[^\r\n]", name, value) != 2) {...} In D? I'm looping through a text file using the File.getline() command and splitting each line into two separate variables with the sscanf command. The if conditional check is to make sure the line is formatted properly (the text file is the settings file for my application). Help please!the quick and wrong way that works is to go find std.c.stdio and call the C sscanf function. (be sure to uses toStringz on the line arg and to allocate for the outputs as you would in c as for a native D equivalent... I'm not sure.
Dec 03 2008