473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Locales, file parsing and isspace, use_facets etc

Hi All,

Is there anyway to change what isspace thinks is a space character.

I am parsing some log files and it would be nice to just read a field as what ever is between quotes or between []'s ie clf log files

I know I can go char by char or find_last_of etc, but I would like to know if it is possible with locales and facets?

Also are there any suggestions for outputting in multiple languages? Can I use locales again?
I was just thinking of a class that has the language set at runtime then outputs the correct text as per the language?

//---------------------------------------------------------------------------

#include <sstream>
#include <string>
#include <locale>
#include <iostream>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
std::stringstream strm("209.167.50.22 - - [25/Jan/2006:02:27:14 -0800] \"GET /Services/Development HTTP/1.1\" 301 352 \"-\" \"LinkWalker\"");
std::string host;
std::string ident;
std::string authuser;
std::string datetime;
std::string http_request;
std::string response_code;
std::string xfer_size;
std::string referer;
std::string agent;

strm >host;
strm >ident;
strm >authuser;
//set the isspace to a ]
strm >datetime;
//set the isspace to a "
strm >http_request;
//set it back to default
strm >response_code;
strm >xfer_size;
//set to "
strm >referer;
strm >agent;

std::cout << "host: " << host << std::endl;
std::cout << "ident: " << ident << std::endl;
std::cout << "authuser: " << authuser << std::endl;
std::cout << "datetime: " << datetime << std::endl;
std::cout << "http_request: " << http_request << std::endl;
std::cout << "response_code: " << response_code << std::endl;
std::cout << "xfer_size: " << xfer_size << std::endl;
std::cout << "referer: " << referer << std::endl;
std::cout << "agent: " << agent << std::endl;

return 0;
}

--

Adrian

Think you know a language? Post to comp.lang... and find out!
Nov 14 '06 #1
2 1858

Adrian wrote:
Hi All,

Is there anyway to change what isspace thinks is a space character.
What? Did you mean use an alternate seperator token(s)? If so, see
below.
>
I am parsing some log files and it would be nice to just read a field as what ever is between quotes or between []'s ie clf log files

I know I can go char by char or find_last_of etc, but I would like to know if it is possible with locales and facets?

Also are there any suggestions for outputting in multiple languages? Can I use locales again?
I was just thinking of a class that has the language set at runtime then outputs the correct text as per the language?

//---------------------------------------------------------------------------

#include <sstream>
#include <string>
#include <locale>
#include <iostream>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
std::stringstream strm("209.167.50.22 - - [25/Jan/2006:02:27:14 -0800] \"GET /Services/Development HTTP/1.1\" 301 352 \"-\" \"LinkWalker\"");
std::string host;
std::string ident;
std::string authuser;
std::string datetime;
std::string http_request;
std::string response_code;
std::string xfer_size;
std::string referer;
std::string agent;

strm >host;
strm >ident;
strm >authuser;
//set the isspace to a ]
strm >datetime;
//set the isspace to a "
strm >http_request;
//set it back to default
strm >response_code;
strm >xfer_size;
//set to "
strm >referer;
strm >agent;

std::cout << "host: " << host << std::endl;
std::cout << "ident: " << ident << std::endl;
std::cout << "authuser: " << authuser << std::endl;
std::cout << "datetime: " << datetime << std::endl;
std::cout << "http_request: " << http_request << std::endl;
std::cout << "response_code: " << response_code << std::endl;
std::cout << "xfer_size: " << xfer_size << std::endl;
std::cout << "referer: " << referer << std::endl;
std::cout << "agent: " << agent << std::endl;

return 0;
}
Use std::getline to break down the istringstream using a delimiter
token:

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <iterator>

int main()
{
std::string stest("this$string$uses$an$alt$sep$token");
std::istringstream iss(stest);

std::vector< std::string vs;
std::string buffer;
while( std::getline(iss, buffer, '$') )
{
vs.push_back(buffer);
}
std::copy( vs.begin(),
vs.end(),
std::ostream_iterator< std::string >(std::cout, "\n") );
}

/*
this
string
uses
an
alt
sep
token
*/

If thats not what you are looking for, then restate your question
clearly.
As far as locales are concerned, lookup imbue.

Nov 14 '06 #2
Salt_Peter wrote:
Adrian wrote:
>Hi All,

Is there anyway to change what isspace thinks is a space character.

What? Did you mean use an alternate seperator token(s)? If so, see
below.
No, I meant can you change the character that isspaces thinks are whitespace. To be honest I thought the question was in plain english.
--

Adrian

Think you know a language? Post to comp.lang... and find out!
Nov 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Adrian Parker | last post by:
I have a server app which is sent a date in the local format of the client machine. I've no control over the client app at all, so have to code at the server end to cope with any problems. The...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
3
by: Eric Lilja | last post by:
Hello, I'm creating a small utility for an online game. It involves parsing a text file of "tradesskill recipes" and inserting these recipes in a gui tree widget (similar to gui file browsers if...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
8
by: Rik | last post by:
Hi all, is there a in PHP to get the available locales without shellacces (i.e. locale -a)? Grtz, -- Rik Wasmus
3
by: Daniel Nogradi | last post by:
Hi list, I have an awk program that parses a text file which I would like to rewrite in python. The text file has multi-line records separated by empty lines and each single-line field has two...
24
by: Marc Dubois | last post by:
hi, is it possible to parse an XML file in C so that i can fulfill these requirements : 1) replace all "<" and ">" signs inside the body of tag by a space, e.g. : Example 1: <fooblabla < bla...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
28
by: pereges | last post by:
Hi I've a string input and I have to parse it in such a way that that there can be only white space till a digit is reached and once a digit is reached, there can be only digits or white space till...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.