* Style cleanup, no functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27005 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-17 14:58:36 +00:00
parent 8ce6cfc999
commit e6a9c269be
+54 -41
View File
@@ -1,21 +1,22 @@
/*
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
* Copyright 2003-2008, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#include <OS.h>
#include <parsedate.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <OS.h>
#define TRACE_PARSEDATE 0
#define TRACE_PARSEDATE 1
#if TRACE_PARSEDATE
# define TRACE(x) printf x ;
# define TRACE(x) debug_printf x ;
#else
# define TRACE(x) ;
#endif
@@ -173,14 +174,21 @@ struct known_identifier {
};
static const known_identifier kIdentifiers[] = {
{"today", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE, UNIT_DAY, 0},
{"tomorrow", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE, UNIT_DAY, 1},
{"yesterday", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE, UNIT_DAY, -1},
{"now", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE | FLAG_NOW, 0},
{"today", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE,
UNIT_DAY, 0},
{"tomorrow", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE,
UNIT_DAY, 1},
{"yesterday", NULL, TYPE_UNIT, FLAG_RELATIVE | FLAG_NOT_MODIFIABLE,
UNIT_DAY, -1},
{"now", NULL, TYPE_UNIT,
FLAG_RELATIVE | FLAG_NOT_MODIFIABLE | FLAG_NOW, 0},
{"this", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE, MODIFY_THIS},
{"next", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE, MODIFY_NEXT},
{"last", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE, MODIFY_LAST},
{"this", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE,
MODIFY_THIS},
{"next", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE,
MODIFY_NEXT},
{"last", NULL, TYPE_MODIFIER, FLAG_NEXT_LAST_THIS, UNIT_NONE,
MODIFY_LAST},
{"years", "year", TYPE_UNIT, FLAG_RELATIVE, UNIT_YEAR, 1},
{"months", "month",TYPE_UNIT, FLAG_RELATIVE, UNIT_MONTH, 1},
@@ -194,7 +202,8 @@ static const known_identifier kIdentifiers[] = {
{"minutes", "mins", TYPE_UNIT, FLAG_RELATIVE, UNIT_SECOND, 60},
{"am", NULL, TYPE_MERIDIAN, FLAG_NOT_MODIFIABLE, UNIT_SECOND, 0},
{"pm", NULL, TYPE_MERIDIAN, FLAG_NOT_MODIFIABLE, UNIT_SECOND, 12 * 60 * 60},
{"pm", NULL, TYPE_MERIDIAN, FLAG_NOT_MODIFIABLE, UNIT_SECOND,
12 * 60 * 60},
{"sunday", "sun", TYPE_WEEKDAY, FLAG_NONE, UNIT_DAY, 0},
{"monday", "mon", TYPE_WEEKDAY, FLAG_NONE, UNIT_DAY, 1},
@@ -218,7 +227,7 @@ static const known_identifier kIdentifiers[] = {
{"december", "dec", TYPE_MONTH, FLAG_NONE, UNIT_MONTH, 12},
{"GMT", NULL, TYPE_TIME_ZONE, FLAG_NONE, UNIT_SECOND, 0},
// ToDo: add more time zones
// TODO: add more time zones
{NULL}
};
@@ -230,7 +239,7 @@ class DateMask {
DateMask() : fMask(0UL) {}
void Set(uint8 type) { fMask |= Flag(type); }
bool IsSet(uint8 type) { return fMask & Flag(type); }
bool IsSet(uint8 type) { return (fMask & Flag(type)) != 0; }
bool HasTime();
bool IsComplete();
@@ -297,7 +306,8 @@ inline bool
parsed_element::IsNextLastThis()
{
return base_type == TYPE_MODIFIER
&& (modifier == MODIFY_NEXT || modifier == MODIFY_LAST || modifier == MODIFY_THIS);
&& (modifier == MODIFY_NEXT || modifier == MODIFY_LAST
|| modifier == MODIFY_THIS);
}
@@ -312,16 +322,15 @@ DateMask::HasTime()
}
/** This method checks if the date mask is complete in the
* sense that it doesn't need to have a prefilled "struct tm"
* when its time value is computed.
/*! This method checks if the date mask is complete in the
sense that it doesn't need to have a prefilled "struct tm"
when its time value is computed.
*/
bool
DateMask::IsComplete()
{
// mask must be absolute, at last
if (fMask & Flag(TYPE_UNIT))
if ((fMask & Flag(TYPE_UNIT)) != 0)
return false;
// minimal set of flags to have a complete set
@@ -332,7 +341,7 @@ DateMask::IsComplete()
// #pragma mark -
status_t
static status_t
preparseDate(const char* dateString, parsed_element* elements)
{
int32 index = 0, modify = MODIFY_NONE;
@@ -389,7 +398,8 @@ preparseDate(const char *dateString, parsed_element *elements)
// check for "1st", "2nd, "3rd", "4th", ...
const char* suffixes[] = {"th", "st", "nd", "rd"};
const char *validSuffix = elements[index].value > 3 ? "th" : suffixes[elements[index].value];
const char* validSuffix = elements[index].value > 3
? "th" : suffixes[elements[index].value];
if (!strncasecmp(dateString + 1, validSuffix, 2)
&& !isalpha(dateString[3])) {
// for now, just ignore the suffix - but we might be able
@@ -504,7 +514,7 @@ computeRelativeUnit(parsed_element &element, struct tm &tm, int *_flags)
// adjust value
if (element.flags & FLAG_RELATIVE) {
if ((element.flags & FLAG_RELATIVE) != 0) {
if (element.unit == UNIT_MONTH)
tm.tm_mon += element.value;
else if (element.unit == UNIT_DAY)
@@ -536,13 +546,13 @@ computeRelativeUnit(parsed_element &element, struct tm &tm, int *_flags)
}
/** Uses the format assignment (through "format", and "optional") for the parsed elements
* and calculates the time value with respect to "now".
* Will also set the day/minute relative flags in "_flags".
/*! Uses the format assignment (through "format", and "optional") for the
parsed elements and calculates the time value with respect to "now".
Will also set the day/minute relative flags in "_flags".
*/
static time_t
computeDate(const char *format, bool *optional, parsed_element *elements, time_t now, DateMask dateMask, int *_flags)
computeDate(const char* format, bool* optional, parsed_element* elements,
time_t now, DateMask dateMask, int* _flags)
{
TRACE(("matches: %s\n", format));
@@ -641,8 +651,9 @@ computeDate(const char *format, bool *optional, parsed_element *elements, time_t
tm.tm_sec += element->value - timezone;
break;
case 'T': // time unit
if (element->flags & FLAG_NOW) {
*_flags = PARSEDATE_MINUTE_RELATIVE_TIME | PARSEDATE_RELATIVE_TIME;
if ((element->flags & FLAG_NOW) != 0) {
*_flags = PARSEDATE_MINUTE_RELATIVE_TIME
| PARSEDATE_RELATIVE_TIME;
break;
}
@@ -681,10 +692,10 @@ parsedate_etc(const char *dateString, time_t now, int *_flags)
for (int32 index = 0; elements[index].type != TYPE_END; index++) {
parsed_element e = elements[index];
printf(" %ld: type = %ld, base_type = %ld, unit = %ld, flags = %ld, value = %Ld (%s)\n",
index, e.type, e.base_type, e.unit, e.flags, e.value,
e.value_type == VALUE_NUMERICAL ? "numerical" :
(e.value_type == VALUE_STRING ? "string" : "char"));
printf(" %ld: type = %u, base_type = %u, unit = %u, flags = %u, "
"value = %Ld (%s)\n", index, e.type, e.base_type, e.unit, e.flags,
e.value, e.value_type == VALUE_NUMERICAL
? "numerical" : (e.value_type == VALUE_STRING ? "string" : "char"));
}
#endif
@@ -775,7 +786,7 @@ parsedate_etc(const char *dateString, time_t now, int *_flags)
dateMask.Set(TYPE_UNIT);
break;
case '-':
if (element->flags & FLAG_HAS_DASH) {
if ((element->flags & FLAG_HAS_DASH) != 0) {
element--; // consider this element again
break;
}
@@ -840,7 +851,8 @@ parsedate_etc(const char *dateString, time_t now, int *_flags)
// skip the closing ']'
}
// check if the format is already empty (since we reached our last element)
// check if the format is already empty (since we reached our last
// element)
while (format[0]) {
if (format[0] == '[')
format += 3;
@@ -854,7 +866,8 @@ parsedate_etc(const char *dateString, time_t now, int *_flags)
// made it here? then we seem to have found our guy
return computeDate(sFormatsTable[index], optional, elements, now, dateMask, _flags);
return computeDate(sFormatsTable[index], optional, elements, now,
dateMask, _flags);
skip_format:
// check if the next format has the same beginning as the skipped one,