Boost logo

Boost Users :

From: Jason Dolan (jason_at_[hidden])
Date: 2006-06-27 12:33:58


Jeff Garland wrote:
> Jason Dolan wrote:
>> Jeff Garland wrote:
>>> Jason Dolan wrote:
>>>> I'm looking to take a string and convert it to a date. The only problem
>>>> is the string can be one of many patterns. i.e. ("%Y%m%d", "%Y-%m-%d",
>>>> "%d/%m/%Y", etc...). It is also possible that the given string will
>>>> fail all pattern matches, and thus return false.
>>> And there's nothing to indicate which pattern it might be?
>> Nope. I'm basically allowing the user to input a date and time *almost*
>> anyway they want. What I want to do is test that string against my list
>> of patterns(i.e. known ways to write a date and time) to try and parse
>> the date.
>
> Well, again some of them are going to be ambiguous. And I'll just say, this
> is a big (read not doable) undertaking. Are all these valid? They certainly
> are to someone somewhere:
>
> june 5 2006
> june 5, 2006
> june 5, 06
> jun 5 //just assume the current year
> junio 5, 2006 //spanish
> 5-jun-2006
> 5-june-2006
> 05-June-2006
> 05 JUNE 2006
> 7/5/6
> 7/6/5
> 5/6/7
> 07/05/06
> 05-07-06
> 05.07.06
> 050706
Yikes! Maybe I'll be a little more restrictive... like force 4 digit
years, etc...

...snip...

>
> You could refactor your code so you don't reallocate the stringstream and
> facet (just reset the strings and formats). But if you really need a high
> level of efficiency, then you're going to just have to bite the bullet and
> write a custom parser. The iostreams solution will always be inherently less
> efficient than custom solutions.
Thats why I was looking into it this way, I was hoping not to have to
create my own parser. I'm actually kinda of surprised that there isn't
a open source natural language date string parser out there already.

>
> Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net