Exemplo n.º 1
0
/*
**    julianday( TIMESTRING, MOD, MOD, ...)
**
** Return the julian day number of the date specified in the arguments
*/
static void juliandayFunc(sqlite_func *context, int argc, const char **argv){
  DateTime x;
  if( isDate(argc, argv, &x)==0 ){
    computeJD(&x);
    sqlite_set_result_double(context, x.rJD);
  }
}
Exemplo n.º 2
0
Date::Date(int yyyy, int mm, int dd){
	if(!isDate(yyyy,mm,dd))
		throw DatabaseException(40, dd + '/' + mm + '/' + yyyy + " is not a valid date.");

	y=yyyy;
	m=mm;
	d=dd;
}
Exemplo n.º 3
0
	Optional<Date> TOMLValue::getOpt<Date>() const
	{
		if (!isDate())
		{
			return none;
		}

		return Optional<Date>(in_place, getDate());
	}
Exemplo n.º 4
0
/*
**    date( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD
*/
static void dateFunc(sqlite_func *context, int argc, const char **argv){
  DateTime x;
  if( isDate(argc, argv, &x)==0 ){
    char zBuf[100];
    computeYMD(&x);
    sprintf(zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
    sqlite_set_result_string(context, zBuf, -1);
  }
}
Exemplo n.º 5
0
/*
**    time( TIMESTRING, MOD, MOD, ...)
**
** Return HH:MM:SS
*/
static void timeFunc(sqlite_func *context, int argc, const char **argv){
  DateTime x;
  if( isDate(argc, argv, &x)==0 ){
    char zBuf[100];
    computeHMS(&x);
    sprintf(zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
    sqlite_set_result_string(context, zBuf, -1);
  }
}
QDate Soprano::LiteralValue::toDate() const
{
    if ( isDate() ) {
        // QVariant::toDate does use the simple ISO format
        return d->value.toDate();
    }
    else {
        return DateTime::fromDateString( toString() );
    }
}
Exemplo n.º 7
0
/*
**    julianday( TIMESTRING, MOD, MOD, ...)
**
** Return the julian day number of the date specified in the arguments
*/
static void juliandayFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  DateTime x;
  if( isDate(context, argc, argv, &x)==0 ){
    computeJD(&x);
    sqlite3_result_double(context, x.iJD/86400000.0);
  }
}
Exemplo n.º 8
0
	date(int d, int m, int y)
	{
		if (isDate(d, m, y))
		{
			day = d;
			month = m;
			year = y;
		}
		else 
			throw badDate();
	}
Exemplo n.º 9
0
	//parses and checks string input
	void parseChk(string input)
	{
		if (isDate(strToInt(input.substr(3, 2)), strToInt(input.substr(0, 2)), strToInt(input.substr(6, input.length() - 6))))
		{
			day = strToInt(input.substr(3, 2));
			month = strToInt(input.substr(0, 2));
			year = strToInt(input.substr(6, input.length() - 6));
		}
		else 
			throw badDate();
	}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
	FILE *input = fopen(argv[1], "r");
	int name_counter = 0, words = 0;
	char buffer[MAX_LINE], *token, delim[] = " ,\t";
	char name[MAX_LINE];

	if (input == NULL){
		return -1;
	}

	while(fgets(buffer, MAX_LINE, input)){
		if (buffer[strlen(buffer) - 1] == '\n'){
			buffer[strlen(buffer) - 1] = '\0';
		}
		token = strtok(buffer, delim);
		while( token != NULL ){
			//printf("%s\n", token);
			if (isDate(token) == 1){
				printf("Found a date: %s\n", token );
			}
			if (isPhoneNumber(token)){
				printf("Found a phone number: %s\n", token );
			}

			if (name_counter == 1 && isName(token) == 0){
				name_counter = 0;
			}
			
			if (isName(token)){
				name_counter++;
				if (name_counter == 2){
					printf("Name found: %s %s\n", name, token );
					name_counter = 0;
				}
				else {
					strcpy(name, token);
				}
			}
			if (isEmail(token)){
				printf("Found an email: %s\n", token );
			}

			
			token = strtok(NULL, delim);
			words++;

		}
		
	}
	printf("There are %d words in the file\n", words );
}
Exemplo n.º 11
0
/*
**    time( TIMESTRING, MOD, MOD, ...)
**
** Return HH:MM:SS
*/
static void timeFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  DateTime x;
  if( isDate(context, argc, argv, &x)==0 ){
    char zBuf[100];
    computeHMS(&x);
    sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
    sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
  }
}
Exemplo n.º 12
0
/*
**    date( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD
*/
static void dateFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  DateTime x;
  if( isDate(context, argc, argv, &x)==0 ){
    char zBuf[100];
    computeYMD(&x);
    sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
    sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
  }
}
Exemplo n.º 13
0
QVariant QScriptValueImpl::toVariant() const
{
    switch (m_type) {
    case QScript::InvalidType:
        return QVariant();

    case QScript::UndefinedType:
    case QScript::NullType:
    case QScript::PointerType:
    case QScript::ReferenceType:
        break;

    case QScript::BooleanType:
        return QVariant(m_bool_value);

    case QScript::IntegerType:
        return QVariant(m_int_value);

    case QScript::NumberType:
        return QVariant(m_number_value);

    case QScript::StringType:
        return QVariant(m_string_value->s);

    case QScript::LazyStringType:
        return QVariant(*m_lazy_string_value);

    case QScript::ObjectType:
        if (isDate())
            return QVariant(toDateTime());

#ifndef QT_NO_REGEXP
        if (isRegExp())
            return QVariant(toRegExp());
#endif
        if (isVariant())
            return variantValue();

#ifndef QT_NO_QOBJECT
        if (isQObject())        
            return qVariantFromValue(toQObject());
#endif

        QScriptValueImpl v = engine()->toPrimitive(*this);
        if (!v.isObject())
            return v.toVariant();
        break;
    } // switch
    return QVariant();
}
Exemplo n.º 14
0
////////////////////////////////////////////////////////////////////////////////
// When a Lexer object is constructed with a string, this method walks through
// the stream of low-level tokens.
bool Lexer::token (std::string& token, Lexer::Type& type)
{
  // Eat white space.
  while (isWhitespace (_text[_cursor]))
    utf8_next_char (_text, _cursor);

  // Terminate at EOS.
  if (isEOS ())
    return false;

  // The sequence is specific, and must follow these rules:
  //   - date < duration < uuid < identifier
  //   - dom < uuid
  //   - uuid < hex < number
  //   - url < pair < identifier
  //   - hex < number
  //   - separator < tag < operator
  //   - path < substitution < pattern
  //   - set < number
  //   - word last
  if (isString       (token, type, "'\"") ||
      isDate         (token, type)        ||
      isDuration     (token, type)        ||
      isURL          (token, type)        ||
      isPair         (token, type)        ||
      isUUID         (token, type, true)  ||
      isSet          (token, type)        ||
      isDOM          (token, type)        ||
      isHexNumber    (token, type)        ||
      isNumber       (token, type)        ||
      isSeparator    (token, type)        ||
      isTag          (token, type)        ||
      isPath         (token, type)        ||
      isSubstitution (token, type)        ||
      isPattern      (token, type)        ||
      isOperator     (token, type)        ||
      isIdentifier   (token, type)        ||
      isWord         (token, type))
    return true;

  return false;
}
Exemplo n.º 15
0
double
CInterval::
interval(int i) const
{
  if       (isDate()) {
    if      (timeType_ == TimeType::YEARS) {
      return yearsToTime(startTime_.year + i*calcIncrement());
    }
    else if (timeType_ == TimeType::MONTHS) {
      return monthsToTime(startTime_, startTime_.month + i*calcIncrement());
    }
    else if (timeType_ == TimeType::DAYS) {
      return daysToTime(startTime_, startTime_.day + i*calcIncrement());
    }
    else {
      return 0;
    }
  }
  else if (isTime()) {
    if      (timeType_ == TimeType::HOURS) {
      return hoursToTime(startTime_, startTime_.hour + i*calcIncrement());
    }
    else if (timeType_ == TimeType::MINUTES) {
      return minutesToTime(startTime_, startTime_.minute + i*calcIncrement());
    }
    else if (timeType_ == TimeType::SECONDS) {
      return secondsToTime(startTime_, startTime_.second + i*calcIncrement());
    }
    else {
      return 0;
    }
  }
  else {
    return valueStart() + i*calcIncrement();
  }
}
Exemplo n.º 16
0
// here we use DataTime instead of QT's built-in time conversion
// since the latter does not properly handle fractions of seconds
// in the ISO8601 specification.
QString Soprano::LiteralValue::toString() const
{
    if ( d ) {
        if ( !d->stringCacheValid ) {
            if( isInt() )
                d->stringCache = QString::number( toInt() );
            else if( isInt64() )
                d->stringCache = QString::number( toInt64() );
            else if( isUnsignedInt() )
                d->stringCache = QString::number( toUnsignedInt() );
            else if( isUnsignedInt64() )
                d->stringCache = QString::number( toUnsignedInt64() );
            else if( isBool() )
                d->stringCache = ( toBool() ? QString("true") : QString("false" ) );
            else if( isDouble() ) // FIXME: decide on a proper double encoding or check if there is one in xml schema
                d->stringCache = QString::number( toDouble(), 'e', 10 );
            else if( isDate() )
                d->stringCache = DateTime::toString( toDate() );
            else if( isTime() )
                d->stringCache = DateTime::toString( toTime() );
            else if( isDateTime() )
                d->stringCache = DateTime::toString( toDateTime() );
            else if ( isByteArray() )
                d->stringCache = QString::fromAscii( toByteArray().toBase64() );
            else
                d->stringCache = d->value.toString();

            d->stringCacheValid = true;
        }

        return d->stringCache;
    }
    else {
        return QString();
    }
}
Exemplo n.º 17
0
/*
**    strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
**
** Return a string described by FORMAT.  Conversions as follows:
**
**   %d  day of month
**   %f  ** fractional seconds  SS.SSS
**   %H  hour 00-24
**   %j  day of year 000-366
**   %J  ** julian day number
**   %m  month 01-12
**   %M  minute 00-59
**   %s  seconds since 1970-01-01
**   %S  seconds 00-59
**   %w  day of week 0-6  sunday==0
**   %W  week of year 00-53
**   %Y  year 0000-9999
**   %%  %
*/
static void strftimeFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  DateTime x;
  u64 n;
  size_t i,j;
  char *z;
  sqlite3 *db;
  const char *zFmt;
  char zBuf[100];
  if( argc==0 ) return;
  zFmt = (const char*)sqlite3_value_text(argv[0]);
  if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
  db = sqlite3_context_db_handle(context);
  for(i=0, n=1; zFmt[i]; i++, n++){
    if( zFmt[i]=='%' ){
      switch( zFmt[i+1] ){
        case 'd':
        case 'H':
        case 'm':
        case 'M':
        case 'S':
        case 'W':
          n++;
          /* fall thru */
        case 'w':
        case '%':
          break;
        case 'f':
          n += 8;
          break;
        case 'j':
          n += 3;
          break;
        case 'Y':
          n += 8;
          break;
        case 's':
        case 'J':
          n += 50;
          break;
        default:
          return;  /* ERROR.  return a NULL */
      }
      i++;
    }
  }
  testcase( n==sizeof(zBuf)-1 );
  testcase( n==sizeof(zBuf) );
  testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
  testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
  if( n<sizeof(zBuf) ){
    z = zBuf;
  }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
    sqlite3_result_error_toobig(context);
    return;
  }else{
    z = sqlite3DbMallocRawNN(db, (int)n);
    if( z==0 ){
      sqlite3_result_error_nomem(context);
      return;
    }
  }
  computeJD(&x);
  computeYMD_HMS(&x);
  for(i=j=0; zFmt[i]; i++){
    if( zFmt[i]!='%' ){
      z[j++] = zFmt[i];
    }else{
      i++;
      switch( zFmt[i] ){
        case 'd':  sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;
        case 'f': {
          double s = x.s;
          if( s>59.999 ) s = 59.999;
          sqlite3_snprintf(7, &z[j],"%06.3f", s);
          j += sqlite3Strlen30(&z[j]);
          break;
        }
        case 'H':  sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
        case 'W': /* Fall thru */
        case 'j': {
          int nDay;             /* Number of days since 1st day of year */
          DateTime y = x;
          y.validJD = 0;
          y.M = 1;
          y.D = 1;
          computeJD(&y);
          nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
          if( zFmt[i]=='W' ){
            int wd;   /* 0=Monday, 1=Tuesday, ... 6=Sunday */
            wd = (int)(((x.iJD+43200000)/86400000)%7);
            sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7);
            j += 2;
          }else{
            sqlite3_snprintf(4, &z[j],"%03d",nDay+1);
            j += 3;
          }
          break;
        }
        case 'J': {
          sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0);
          j+=sqlite3Strlen30(&z[j]);
          break;
        }
        case 'm':  sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
        case 'M':  sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
        case 's': {
          sqlite3_snprintf(30,&z[j],"%lld",
                           (i64)(x.iJD/1000 - 21086676*(i64)10000));
          j += sqlite3Strlen30(&z[j]);
          break;
        }
        case 'S':  sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
        case 'w': {
          z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
          break;
        }
        case 'Y': {
          sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]);
          break;
        }
        default:   z[j++] = '%'; break;
      }
    }
  }
  z[j] = 0;
  sqlite3_result_text(context, z, -1,
                      z==zBuf ? SQLITE_TRANSIENT : SQLITE_DYNAMIC);
}
Exemplo n.º 18
0
int _parseArgs(PyObject **args, int count, const char *types, va_list list)
#endif
{
    if (count != strlen(types))
        return -1;

#else

int _parseArgs(PyObject **args, int count, const char *types, ...)
{
    va_list list;

    if (count != (int) strlen(types))
        return -1;

    va_start(list, types);

#endif

    if (PyErr_Occurred())
        return -1;

    for (int i = 0; i < count; i++) {
#ifdef PYPY_VERSION
        PyObject *arg = PyTuple_GetItem(args, i);
#else
        PyObject *arg = args[i];
#endif
        
        switch (types[i]) {
          case 'c':           /* string */
          case 'k':           /* string and size */
          case 'C':           /* string, not to be unpacked */
            if (PyBytes_Check(arg))
                break;
            return -1;

          case 's':           /* string or unicode, to UnicodeString ref */
          case 'u':           /* string or unicode, to new UnicodeString ptr */
          case 'n':           /* string or unicode, to utf8 charsArg */
          case 'f':           /* string or unicode filename, to charsArg */
            if (PyBytes_Check(arg) || PyUnicode_Check(arg))
                break;
            return -1;

          case 'S':           /* string, unicode or UnicodeString */
          case 'W':           /* string, unicode or UnicodeString, to save */
            if (PyBytes_Check(arg) || PyUnicode_Check(arg) ||
                isUnicodeString(arg))
                break;
            return -1;

          case 'T':           /* array of string, unicode or UnicodeString */
            if (PySequence_Check(arg))
            {
                if (PySequence_Length(arg) > 0)
                {
                    PyObject *obj = PySequence_GetItem(arg, 0);
                    int ok = (PyBytes_Check(obj) || PyUnicode_Check(obj) ||
                              isUnicodeString(obj));
                    Py_DECREF(obj);
                    if (ok)
                        break;
                }
                else
                    break;
            }
            return -1;

          case 'U':           /* UnicodeString */
          case 'V':           /* UnicodeString and raw arg object */
            if (isUnicodeString(arg))
                break;
            return -1;

          case 'K':           /* python object of any type */
              break;

          case 'M':           /* python callable */
          {
              if (PyCallable_Check(arg))
                  break;
              return -1;
          }

          case 'O':           /* python object of given type */
          {
              PyTypeObject *type = va_arg(list, PyTypeObject *);

              if (PyObject_TypeCheck(arg, type))
                  break;
              return -1;
          }

          case 'P':           /* wrapped ICU object */
          case 'p':           /* wrapped ICU object, to save */
          {
              classid id = va_arg(list, classid);
              PyTypeObject *type = va_arg(list, PyTypeObject *);

              if (isInstance(arg, id, type))
                  break;
              return -1;
          }

          case 'Q':           /* array of wrapped ICU object pointers */
          case 'R':           /* array of wrapped ICU objects */
          {
              classid id = va_arg(list, classid);
              PyTypeObject *type = va_arg(list, PyTypeObject *);
              
              if (PySequence_Check(arg))
              {
                  if (PySequence_Length(arg) > 0)
                  {
                      PyObject *obj = PySequence_GetItem(arg, 0);
                      int ok = isInstance(obj, id, type);

                      Py_DECREF(obj);
                      if (ok)
                          break;
                  }
                  else
                      break;
              }
              return -1;
          }

          case 'D':           /* date as UDate float or datetime */
            if (isDate(arg))
                break;
            return -1;

          case 'E':           /* date as datetime */
            if (isDateExact(arg))
                break;
            return -1;

          case 'a':           /* byte */
            if (PyBytes_Check(arg) && (PyBytes_Size(arg) == 1))
                break;
            return -1;

          case 'B':           /* boolean, strict */
            if (arg == Py_True || arg == Py_False)
                break;
            return -1;

          case 'b':           /* boolean */
            break;

          case 'i':           /* int */
            if (PyInt_Check(arg))
                break;
            return -1;

          case 'd':           /* double */
            if (PyFloat_Check(arg) || PyInt_Check(arg) || PyLong_Check(arg))
                break;
            return -1;

          case 'F':           /* array of double */
            if (PySequence_Check(arg))
            {
                if (PySequence_Length(arg) > 0)
                {
                    PyObject *obj = PySequence_GetItem(arg, 0);
                    int ok = (PyFloat_Check(obj) ||
                              PyInt_Check(obj) ||
                              PyLong_Check(obj));
                    Py_DECREF(obj);
                    if (ok)
                        break;
                }
                else
                    break;
            }
            return -1;

          case 'G':           /* array of bool */
            if (PySequence_Check(arg))
                break;
            return -1;

          case 'L':           /* PY_LONG_LONG */
            if (PyLong_Check(arg) || PyInt_Check(arg))
                break;
            return -1;

          default:
            return -1;
        }
    }

    for (int j = 0; j < count; j++) {
#ifdef PYPY_VERSION
        PyObject *arg = PyTuple_GetItem(args, j);
#else
        PyObject *arg = args[j];
#endif
        switch (types[j]) {
          case 'A':           /* previous Python arg object */
          {
              PyObject **obj = va_arg(list, PyObject **);
#ifdef PYPY_VERSION
              *obj = PyTuple_GetItem(args, j - 1);
#else
              *obj = args[j - 1];
#endif
              break;
          }
            
          case 'c':           /* string */
          {
              char **c = va_arg(list, char **);
              *c = PyBytes_AS_STRING(arg);
              break;
          }

          case 'k':           /* string and size */
          {
              char **c = va_arg(list, char **);
              int *l = va_arg(list, int *);
              *c = PyBytes_AS_STRING(arg);
              *l = PyBytes_GET_SIZE(arg);
              break;
          }

          case 'C':           /* string, not to be unpacked */
          {
              PyObject **obj = va_arg(list, PyObject **);
              *obj = arg;
              break;
          }

          case 's':           /* string or unicode, to UnicodeString ref */
          {
              UnicodeString *u = va_arg(list, UnicodeString *);

              try {
                  PyObject_AsUnicodeString(arg, *u);
              } catch (ICUException e) {
                  e.reportError();
                  return -1;
              }
              break;
          }

          case 'u':           /* string or unicode, to new UnicodeString ptr */
          {
              UnicodeString **u = va_arg(list, UnicodeString **);

              try {
                  *u = PyObject_AsUnicodeString(arg);
              } catch (ICUException e) {
                  e.reportError();
                  return -1;
              }
              break;
          }

          case 'n':           /* string or unicode, to utf8 charsArg */
          {
              charsArg *p = va_arg(list, charsArg *);

              if (PyUnicode_Check(arg))
              {
                  PyObject *bytes = PyUnicode_AsUTF8String(arg);
                  if (bytes == NULL)
                      return -1;
                  p->own(bytes);
              }
              else
              {
                  p->borrow(arg);
              }
              break;
          }

          case 'f':           /* string or unicode filename, to charsArg */
          {
              charsArg *p = va_arg(list, charsArg *);

              if (PyUnicode_Check(arg))
              {
#if PY_MAJOR_VERSION >= 3
                  PyObject *bytes = PyUnicode_EncodeFSDefault(arg);
#else
                  // TODO: Figure out fs encoding in a reasonable way
                  PyObject *bytes = PyUnicode_AsUTF8String(arg);
#endif
                  if (bytes == NULL)
                      return -1;
                  p->own(bytes);
              }
              else
              {
                  p->borrow(arg);
              }
              break;
          }

          case 'S':           /* string, unicode or UnicodeString */
          {
              UnicodeString **u = va_arg(list, UnicodeString **);
              UnicodeString *_u = va_arg(list, UnicodeString *);

              if (PyObject_TypeCheck(arg, &UObjectType_))
                  *u = (UnicodeString *) ((t_uobject *) arg)->object;
              else
              {
                  try {
                      PyObject_AsUnicodeString(arg, *_u);
                      *u = _u;
                  } catch (ICUException e) {
                      e.reportError();
                      return -1;
                  }
              }
              break;
          }

          case 'W':           /* string, unicode or UnicodeString, to save */
          {
              UnicodeString **u = va_arg(list, UnicodeString **);
              PyObject **obj = va_arg(list, PyObject **);

              if (PyObject_TypeCheck(arg, &UObjectType_))
              {
                  *u = (UnicodeString *) ((t_uobject *) arg)->object;
                  Py_INCREF(arg); Py_XDECREF(*obj); *obj = arg;
              }
              else
              {
                  try {
                      *u = PyObject_AsUnicodeString(arg);
                      Py_XDECREF(*obj); *obj = wrap_UnicodeString(*u, T_OWNED);
                  } catch (ICUException e) {
                      e.reportError();
                      return -1;
                  }
              }
              break;
          }

          case 'T':           /* array of string, unicode or UnicodeString */
          {
              UnicodeString **array = va_arg(list, UnicodeString **);
              int *len = va_arg(list, int *);
              *array = toUnicodeStringArray(arg, len);
              if (!*array)
                  return -1;
              break;
          }

          case 'U':           /* UnicodeString */
          {
              UnicodeString **u = va_arg(list, UnicodeString **);
              *u = (UnicodeString *) ((t_uobject *) arg)->object;
              break;
          }

          case 'V':           /* UnicodeString and raw arg object */
          {
              UnicodeString **u = va_arg(list, UnicodeString **);
              PyObject **obj = va_arg(list, PyObject **);
              *u = (UnicodeString *) ((t_uobject *) arg)->object;
              *obj = arg;
              break;
          }

          case 'K':           /* python object of any type */
          case 'M':           /* python callable */
          case 'O':           /* python object of given type */
          {
              PyObject **obj = va_arg(list, PyObject **);
              *obj = arg;
              break;
          }

          case 'P':           /* wrapped ICU object */
          {
              UObject **obj = va_arg(list, UObject **);
              *obj = ((t_uobject *) arg)->object;
              break;
          }

          case 'p':           /* wrapped ICU object, to save */
          {
              UObject **obj = va_arg(list, UObject **);
              PyObject **pyobj = va_arg(list, PyObject **);
              *obj = ((t_uobject *) arg)->object;
              Py_INCREF(arg); Py_XDECREF(*pyobj); *pyobj = arg;
              break;
          }

          case 'Q':           /* array of wrapped ICU object pointers */
          {
              UObject ***array = va_arg(list, UObject ***);
              int *len = va_arg(list, int *);
              classid id = va_arg(list, classid);
              PyTypeObject *type = va_arg(list, PyTypeObject *);
              *array = pl2cpa(arg, len, id, type);
              if (!*array)
                  return -1;
              break;
          }

          case 'R':           /* array of wrapped ICU objects */
          {
              typedef UObject *(*convFn)(PyObject *, int *,
                                         classid, PyTypeObject *);
              UObject **array = va_arg(list, UObject **);
              int *len = va_arg(list, int *);
              classid id = va_arg(list, classid);
              PyTypeObject *type = va_arg(list, PyTypeObject *);
              convFn fn = va_arg(list, convFn);
              *array = fn(arg, len, id, type);
              if (!*array)
                  return -1;
              break;
          }

          case 'D':           /* date as UDate float or datetime */
          case 'E':           /* date as datetime */
          {
              UDate *d = va_arg(list, UDate *);
              *d = PyObject_AsUDate(arg);
              break;
          }

          case 'a':           /* byte */
          {
              unsigned char *a = va_arg(list, unsigned char *);
              *a = (unsigned char) PyBytes_AS_STRING(arg)[0];
              break;
          }

          case 'B':           /* boolean, strict */
          case 'b':           /* boolean */
          {
              int *b = va_arg(list, int *);
              *b = PyObject_IsTrue(arg);
              break;
          }

          case 'i':           /* int */
          {
              int *n = va_arg(list, int *);
#if PY_MAJOR_VERSION >= 3
              if ((*n = PyLong_AsLong(arg)) == -1 && PyErr_Occurred())
                  return -1;
#else
              *n = PyInt_AsLong(arg);
#endif
              break;
          }

          case 'd':           /* double */
          {
              double *d = va_arg(list, double *);
              if (PyFloat_Check(arg))
                  *d = PyFloat_AsDouble(arg);
#if PY_MAJOR_VERSION < 3
              else if (PyInt_Check(arg))
                  *d = (double) PyInt_AsLong(arg);
#endif
              else
                  *d = PyLong_AsDouble(arg);
              break;
          }

          case 'F':           /* array of double */
          {
              double **array = va_arg(list, double **);
              int *len = va_arg(list, int *);
              *array = toDoubleArray(arg, len);
              if (!*array)
                  return -1;
              break;
          }

          case 'G':           /* array of UBool */
          {
              UBool **array = va_arg(list, UBool **);
              int *len = va_arg(list, int *);
              *array = toUBoolArray(arg, len);
              if (!*array)
                  return -1;
              break;
          }

          case 'L':           /* PY_LONG_LONG */
          {
              PY_LONG_LONG *l = va_arg(list, PY_LONG_LONG *);
              *l = PyLong_AsLongLong(arg);
              break;
          }

          default:
            return -1;
        }
    }

    return 0;
}
Exemplo n.º 19
0
void
CInterval::
init()
{
  bool integral = isIntegral();

  timeType_ = TimeType::SECONDS;

  startTime_.year   = 0;
  startTime_.month  = 0;
  startTime_.day    = 0;
  startTime_.hour   = 0;
  startTime_.minute = 0;
  startTime_.second = 0;

  // Ensure min/max are in the correct order
  double min = std::min(data_.start, data_.end);
  double max = std::max(data_.start, data_.end);

  if      (isIntegral()) {
    min = std::floor(min);
    max = std::ceil (max);
  }
  else if (isDate()) {
    int y = timeLengthToYears  (min, max);
    int m = timeLengthToMonths (min, max);
    int d = timeLengthToDays   (min, max);

    startTime_.year  = timeToYear   (min);
    startTime_.month = timeToMonths (min);
    startTime_.day   = timeToDays   (min);

    min = 0;

    if      (y >= 5) {
      //std::cout << "years\n";
      timeType_ = TimeType::YEARS;
      max       = y;
    }
    else if (m >= 3) {
      //std::cout << "months\n";
      timeType_ = TimeType::MONTHS;
      max       = m;
    }
    else if (d >= 4) {
      //std::cout << "days\n";
      timeType_ = TimeType::DAYS;
      max       = d;
    }

    integral = true;
  }
  else if (isTime()) {
    int h = timeLengthToHours  (min, max);
    int m = timeLengthToMinutes(min, max);
    int s = timeLengthToSeconds(min, max);

    startTime_.hour   = timeToHours  (min);
    startTime_.minute = timeToMinutes(min);
    startTime_.second = timeToSeconds(min);

    min = 0;

    if      (h >= 12) {
      //std::cout << "hours\n";
      timeType_ = TimeType::HOURS;
      max       = h;
    }
    else if (m >= 10) {
      //std::cout << "minutes\n";
      timeType_ = TimeType::MINUTES;
      max       = m;
    }
    else {
      //std::cout << "seconds\n";
      timeType_ = TimeType::SECONDS;
      max       = s;
    }

    integral = true;
  }

  //---

  // use fixed increment
  double majorIncrement = this->majorIncrement();

  if (majorIncrement > 0.0 && (! isDate() && ! isTime())) {
    calcData_.start     = min;
    calcData_.end       = max;
    calcData_.increment = majorIncrement;

    calcData_.numMajor =
      CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment);
    calcData_.numMinor = 5;

    return;
  }

  //---

  if (data_.numMajor > 0) {
    goodTicks_.opt = data_.numMajor;
    goodTicks_.min = std::max(goodTicks_.opt/10, 1);
    goodTicks_.max = goodTicks_.opt*10;
  }
  else {
    goodTicks_ = GoodTicks();
  }

  //---

  calcData_.numMajor = -1;
  calcData_.numMinor = 5;

  //---

  calcData_.increment = data_.increment;

  if (calcData_.increment <= 0.0) {
    calcData_.increment = initIncrement(min, max, integral);

    //---

    // Calculate other test increments
    for (int i = 0; i < numIncrementTests; i++) {
      // disable non-integral increments for integral
      if (integral && ! isInteger(incrementTests[i].factor)) {
        incrementTests[i].incFactor = 0.0;
        continue;
      }

      // disable non-log increments for log
      if (isLog() && ! incrementTests[i].isLog) {
        incrementTests[i].incFactor = 0.0;
        continue;
      }

      incrementTests[i].incFactor = calcData_.increment*incrementTests[i].factor;
    }

    //---

    // Test each increment in turn (Set default start/end to force update)
    int tickIncrement = this->tickIncrement();

    GapData axisGapData;

    for (int i = 0; i < numIncrementTests; i++) {
      // skip disable tests
      if (incrementTests[i].incFactor <= 0.0)
        continue;

      // if tick increment set then skip if not multiple of increment
      if (tickIncrement > 0) {
        if (! isInteger(incrementTests[i].incFactor))
          continue;

        int incFactor1 = int(incrementTests[i].incFactor);

        if (incFactor1 % tickIncrement != 0)
          continue;
      }

      // test factor, ticks and update best
      if (testAxisGaps(min, max,
                       incrementTests[i].incFactor,
                       incrementTests[i].numTicks,
                       axisGapData)) {
        //axisGapData.print("  Best) ");
      }
    }

    //---

    calcData_.start     = axisGapData.start;
    calcData_.end       = axisGapData.end;
    calcData_.increment = axisGapData.increment;
    calcData_.numMinor  = (! isLog() ? axisGapData.numMinor : 10);
  }
  else {
    calcData_.start    = min;
    calcData_.end      = max;
    calcData_.numMinor = 5;
  }

  calcData_.numMajor =
    CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment);

  if      (isDate()) {
    if      (timeType_ == TimeType::YEARS) {
      calcData_.numMinor = 12;
    }
    else if (timeType_ == TimeType::MONTHS) {
      calcData_.numMinor = 4;
    }
    else if (timeType_ == TimeType::DAYS) {
      calcData_.numMinor = 4;
    }
  }
  else if (isTime()) {
    if      (timeType_ == TimeType::HOURS) {
      calcData_.numMinor = 6;
    }
    else if (timeType_ == TimeType::MINUTES) {
      calcData_.numMinor = 12;
    }
    else if (timeType_ == TimeType::SECONDS) {
      calcData_.numMinor = 12;
    }
  }
}
Exemplo n.º 20
0
/*
**    strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
**
** Return a string described by FORMAT.  Conversions as follows:
**
**   %d  day of month
**   %f  ** fractional seconds  SS.SSS
**   %H  hour 00-24
**   %j  day of year 000-366
**   %J  ** Julian day number
**   %m  month 01-12
**   %M  minute 00-59
**   %s  seconds since 1970-01-01
**   %S  seconds 00-59
**   %w  day of week 0-6  sunday==0
**   %W  week of year 00-53
**   %Y  year 0000-9999
**   %%  %
*/
static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
  DateTime x;
  int n, i, j;
  char *z;
  const char *zFmt = argv[0];
  char zBuf[100];
  if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;
  for(i=0, n=1; zFmt[i]; i++, n++){
    if( zFmt[i]=='%' ){
      switch( zFmt[i+1] ){
        case 'd':
        case 'H':
        case 'm':
        case 'M':
        case 'S':
        case 'W':
          n++;
          /* fall thru */
        case 'w':
        case '%':
          break;
        case 'f':
          n += 8;
          break;
        case 'j':
          n += 3;
          break;
        case 'Y':
          n += 8;
          break;
        case 's':
        case 'J':
          n += 50;
          break;
        default:
          return;  /* ERROR.  return a NULL */
      }
      i++;
    }
  }
  if( n<sizeof(zBuf) ){
    z = zBuf;
  }else{
    z = sqliteMalloc( n );
    if( z==0 ) return;
  }
  computeJD(&x);
  computeYMD_HMS(&x);
  for(i=j=0; zFmt[i]; i++){
    if( zFmt[i]!='%' ){
      z[j++] = zFmt[i];
    }else{
      i++;
      switch( zFmt[i] ){
        case 'd':  sprintf(&z[j],"%02d",x.D); j+=2; break;
        case 'f': {
          int s = x.s;
          int ms = (x.s - s)*1000.0;
          sprintf(&z[j],"%02d.%03d",s,ms);
          j += strlen(&z[j]);
          break;
        }
        case 'H':  sprintf(&z[j],"%02d",x.h); j+=2; break;
        case 'W': /* Fall thru */
        case 'j': {
          int n;
          DateTime y = x;
          y.validJD = 0;
          y.M = 1;
          y.D = 1;
          computeJD(&y);
          n = x.rJD - y.rJD + 1;
          if( zFmt[i]=='W' ){
            sprintf(&z[j],"%02d",(n+6)/7);
            j += 2;
          }else{
            sprintf(&z[j],"%03d",n);
            j += 3;
          }
          break;
        }
        case 'J':  sprintf(&z[j],"%.16g",x.rJD); j+=strlen(&z[j]); break;
        case 'm':  sprintf(&z[j],"%02d",x.M); j+=2; break;
        case 'M':  sprintf(&z[j],"%02d",x.m); j+=2; break;
        case 's': {
          sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));
          j += strlen(&z[j]);
          break;
        }
        case 'S':  sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;
        case 'w':  z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
        case 'Y':  sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;
        case '%':  z[j++] = '%'; break;
      }
    }
  }
  z[j] = 0;
  sqlite_set_result_string(context, z, -1);
  if( z!=zBuf ){
    sqliteFree(z);
  }
}
Exemplo n.º 21
0
//--------------------------------------------------------------
void guiPubMed::updateRequest(){
	
	newEvent.query=""; //My event to fill and send
	string conjuctiontype;
	string reftype;
	string text;
	string datafrom;
	string dataTo;
	string datetype = "&datetype=";
	string sMindate = "&mindate=";
	string sMaxdate = "&maxdate=";
	string sTerm = "&term=";
	string bwtdates = "%3A";
		
	ofLogVerbose("guiPubMed") <<"updateRequest num searchBars from [0..X] = " << searchBars << endl;
	
	int searchBarsFilled = countDataFilled() -1;//Array format
	ofLogVerbose("guiPubMed") <<"searchBarsFilled from [0..X] = " << searchBarsFilled << endl;
		
	newEvent.query += sTerm; //set term questionarie
	
	//Set all open brakets for each searchBarsFilled
	string openBraket = "(";
	for (int i = 0; i <= searchBarsFilled; i++) newEvent.query += openBraket;
	
	//Add inputtext + searchType + ) + ADN/OR/NOT
	for (int i = 0 ; i <= searchBars; i++){
		
		//Check all params to set right for each mode ( search or textField )
		conjuctiontype = conjuctiontypeString[i];
		reftype = reftypeString[i];
		
		if(conjuctiontype.empty())conjuctiontype = "+AND+";
		if(i == 0)conjuctiontype = ""; //but avoid to set +AND+ at fisrt query item
		if(reftype.empty())reftype = "[All%20Fields]";
		
		string closeBraket = "";
		closeBraket = ")";
		
		if(!myDataTypeSelected[i]){ //normal textField data type
			text =  textString[i];
			if(!text.empty()){
				newEvent.query += conjuctiontype + text + reftype + closeBraket;
			}
		}
		else { //date type
			string openBraketdate = "(";
			string closeBraketdate = ")";
			
			datafrom = fromDateString[i];
			bool bdate = isDate(datafrom);
			dataTo = toDateString[i];
			if(dataTo.empty())dataTo = getPresentData();

			if(!datafrom.empty() && bdate){
				newEvent.query += conjuctiontype + openBraketdate + datafrom + reftype + bwtdates + dataTo + reftype + closeBraketdate + closeBraket;
			}
		}
				
		ofLogVerbose("guiPubMed") << "Current query: " << newEvent.query << "I=" << i << endl;
	}
}