예제 #1
0
LogDecorators::Decorator LogDecorators::from_string(const char* str) {
  for (size_t i = 0; i < Count; i++) {
    Decorator d = static_cast<Decorator>(i);
    if (strcasecmp(str, name(d)) == 0 || strcasecmp(str, abbreviation(d)) == 0) {
      return d;
    }
  }
  return Invalid;
}
QTimeZonePrivate::Data QAndroidTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
{
    if (androidTimeZone.isValid()) {
        Data data;
        data.atMSecsSinceEpoch = forMSecsSinceEpoch;
        data.standardTimeOffset = standardTimeOffset(forMSecsSinceEpoch);
        data.offsetFromUtc = offsetFromUtc(forMSecsSinceEpoch);
        data.daylightTimeOffset = data.offsetFromUtc - data.standardTimeOffset;
        data.abbreviation = abbreviation(forMSecsSinceEpoch);
        return data;
    } else {
        return invalidData();
    }
}
예제 #3
0
QTimeZonePrivate::Data QIcuTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
{
    // Available in ICU C++ api, and draft C api in v50
    // TODO When v51 released see if api is stable
    QTimeZonePrivate::Data data = invalidData();
#if U_ICU_VERSION_MAJOR_NUM == 50
    data = ucalTimeZoneTransition(m_ucal, UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE,
                                  forMSecsSinceEpoch);
#else
    ucalOffsetsAtTime(m_ucal, forMSecsSinceEpoch, &data.standardTimeOffset,
                      &data.daylightTimeOffset);
    data.offsetFromUtc = data.standardTimeOffset + data.daylightTimeOffset;
    data.abbreviation = abbreviation(forMSecsSinceEpoch);
#endif // U_ICU_VERSION_MAJOR_NUM == 50
    data.atMSecsSinceEpoch = forMSecsSinceEpoch;
    return data;
}
예제 #4
0
파일: units.cpp 프로젝트: mcirsta/lignumCAD
  QString format ( enum UnitFormat format, int precision, double value,
		   bool use_unicode ) const
  {
    switch ( format ) {
    case FRACTIONAL:
      {
	// The limit of fractional values to 1/256-ths is hardcoded.
	QString formatted_value;
	if ( fabs( value ) < 1./256. )
	  formatted_value = "0";
	else {
	  // Extract the integral part
	  int a = (int)value;

	  if ( a != 0 )
	    formatted_value = QString::number( a );

	  // Extract the fractional part: NOTE: THIS IS LIMITED TO
	  // REPRESENTING ALL FRACTIONS AS n/256!
	  int b = (int)rint( 256 * fabs( value - a ) );

	  // If b is exactly 256, then the original number was essentially
	  // an integer (to withing 1/256-th)
	  if ( b == 256 )
	    formatted_value = QString::number( rint( value ) );

	  else if ( b != 0 ) {
	    int c = 256;

	    if ( !formatted_value.isEmpty() )
	      formatted_value += QChar( 0xa0 );
	    else if ( value < 0 )
	      formatted_value = "-";

	    // If required, shift to the 0xE000 private UNICODE
	    // page using the old trick of subtracting the character '0'
	    // from another numeric character to find the integral value.
	    ushort num_unicode_offset =
	      lC::UNICODE_PRIVATE_PAGE - QChar('0').unicode();
	    ushort den_unicode_offset =
	      lC::UNICODE_PRIVATE_PAGE + 0x10 - QChar('0').unicode();

	    if ( !use_unicode ) {
	      num_unicode_offset = 0;
	      den_unicode_offset = 0;
	    }

	    // Remove common factors of two from the numerator and denominator
	    // (i.e. (b&1) == 0 implies b is even)
	    for ( ; ( b & 1 ) == 0; b >>= 1, c >>= 1 );

	    // Format the numerator and shift to the 0xE000 sequence
	    QString numerator = QString::number( b );
        for ( int i = 0; i < numerator.length(); i++ )
          numerator[i] = QChar( numerator.at(i).unicode() +
				       num_unicode_offset );
	    formatted_value += numerator;
	    formatted_value += use_unicode ?
	      QChar( 0xE00a ) // The custom '/' character
	      : QChar( '/' );
	    // Format the denominator and shift to the 0xE010 sequence
	    QString denominator = QString::number( c );
        for ( int i = 0; i < denominator.length(); i++ )
          denominator[i] = QChar( denominator.at(i).unicode() +
					 den_unicode_offset );
	    formatted_value += denominator;
	  }
	}
	// Finally, tack on the abbreviation
	return lC::STR::VALUE_UNIT.arg( formatted_value ).arg( abbreviation() );
      }
    case DECIMAL:
      {
	return lC::STR::VALUE_UNIT.arg( value, 0, 'f', precision).arg(abbreviation());
      }
    }