Exemple #1
0
Length* newLengthArray(const String& string, int& len)
{
    RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace();
    if (!str->length()) {
        len = 1;
        return 0;
    }

    len = countCharacter(str->characters(), str->length(), ',') + 1;
    Length* r = new Length[len];

    int i = 0;
    int pos = 0;
    int pos2;

    while ((pos2 = str->find(',', pos)) != -1) {
        r[i++] = parseLength(str->characters() + pos, pos2 - pos);
        pos = pos2+1;
    }

    ASSERT(i == len - 1);

    // IE Quirk: If the last comma is the last char skip it and reduce len by one.
    if (str->length()-pos > 0)
        r[i] = parseLength(str->characters() + pos, str->length() - pos);
    else
        len--;

    return r;
}
Exemple #2
0
Length* newCoordsArray(const String& string, int& len)
{
    unsigned length = string.length();
    const UChar* data = string.characters();
    StringBuffer spacified(length);
    for (unsigned i = 0; i < length; i++) {
        UChar cc = data[i];
        if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
            spacified[i] = ' ';
        else
            spacified[i] = cc;
    }
    RefPtr<StringImpl> str = StringImpl::adopt(spacified);

    str = str->simplifyWhiteSpace();

    len = countCharacter(str->characters(), str->length(), ' ') + 1;
    Length* r = new Length[len];

    int i = 0;
    int pos = 0;
    int pos2;

    while ((pos2 = str->find(' ', pos)) != -1) {
        r[i++] = parseLength(str->characters() + pos, pos2 - pos);
        pos = pos2+1;
    }
    r[i] = parseLength(str->characters() + pos, str->length() - pos);

    ASSERT(i == len - 1);

    return r;
}
Exemple #3
0
std::unique_ptr<Length[]> newCoordsArray(const String& string, int& len)
{
    unsigned length = string.length();
    StringBuffer<UChar> spacified(length);
    for (unsigned i = 0; i < length; i++) {
        UChar cc = string[i];
        if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
            spacified[i] = ' ';
        else
            spacified[i] = cc;
    }
    RefPtr<StringImpl> str = StringImpl::adopt(spacified);

    str = str->simplifyWhiteSpace();

    len = countCharacter(*str, ' ') + 1;
    auto r = std::make_unique<Length[]>(len);

    int i = 0;
    unsigned pos = 0;
    size_t pos2;

    auto upconvertedCharacters = StringView(str.get()).upconvertedCharacters();
    while ((pos2 = str->find(' ', pos)) != notFound) {
        r[i++] = parseLength(upconvertedCharacters + pos, pos2 - pos);
        pos = pos2+1;
    }
    r[i] = parseLength(upconvertedCharacters + pos, str->length() - pos);

    ASSERT(i == len - 1);

    return r;
}
Exemple #4
0
std::unique_ptr<Length[]> newLengthArray(const String& string, int& len)
{
    RefPtr<StringImpl> str = string.impl()->simplifyWhiteSpace();
    if (!str->length()) {
        len = 1;
        return nullptr;
    }

    len = countCharacter(*str, ',') + 1;
    auto r = std::make_unique<Length[]>(len);

    int i = 0;
    unsigned pos = 0;
    size_t pos2;

    auto upconvertedCharacters = StringView(str.get()).upconvertedCharacters();
    while ((pos2 = str->find(',', pos)) != notFound) {
        r[i++] = parseLength(upconvertedCharacters + pos, pos2 - pos);
        pos = pos2+1;
    }

    ASSERT(i == len - 1);

    // IE Quirk: If the last comma is the last char skip it and reduce len by one.
    if (str->length()-pos > 0)
        r[i] = parseLength(upconvertedCharacters + pos, str->length() - pos);
    else
        len--;

    return r;
}
Exemple #5
0
bool esvg::Rectangle::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
	if (_element.exist() == false) {
		return false;
	}
	m_position.setValue(0.0f, 0.0f);
	m_size.setValue(0.0f, 0.0f);
	m_roundedCorner.setValue(0.0f, 0.0f);
	
	parseTransform(_element);
	parsePaintAttr(_element);
	
	// add the property of the parrent modifications ...
	m_transformMatrix *= _parentTrans;
	
	parsePosition(_element, m_position, m_size);
	
	std::string content = _element.attributes["rx"];
	if (content.size()!=0) {
		m_roundedCorner.setX(parseLength(content));
	}
	content = _element.attributes["ry"];
	if (content.size()!=0) {
		m_roundedCorner.setY(parseLength(content));
	}
	_sizeMax.setValue(m_position.x() + m_size.x() + m_paint.strokeWidth,
	                  m_position.y() + m_size.y() + m_paint.strokeWidth);
	return true;
}
Exemple #6
0
int32 parseTLV(const uint8 *msg, int32 index, tlvStructType *tlv)
{
	int32 Llen = 0;

	tlv->start = index;

	Llen = parseLength((const uint8 *)&msg[index+1], &tlv->len );

	tlv->vstart = index + Llen + 1;

	switch (msg[index])
	{
	case SNMPDTYPE_SEQUENCE:
	case GET_REQUEST:
	case GET_NEXT_REQUEST:
	case SET_REQUEST:
		tlv->nstart = tlv->vstart;
		break;
	default:
		tlv->nstart = tlv->vstart + tlv->len;
		break;
	}

	return 0;
}
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName) {
	StyleSheetTable::AttributeMap::const_iterator it = map.find(attributeName);
	if (it == map.end()) {
		return;
	}
	const std::vector<std::string> &values = it->second;
	if (!values.empty() && !values[0].empty()) {
		short size;
		ZLTextStyleEntry::SizeUnit unit;
		parseLength(values[0], size, unit);
		entry.setLength(name, size, unit);
	}
}
Exemple #8
0
RouteNew* parseRoute(QXmlStreamReader &reader)
{
    QDateTime routeStartTime;
    QDateTime routeEndTime;
    RoutePoint *routeStartPoint;
    RoutePoint *routeEndPoint;
    double routeWalkingDistance = 0.0;
    double routeDistance;
    QList<RouteLeg*> routeSubRoute;

    //qDebug() << "Parsing route";
    while (!reader.atEnd() && !(reader.name() == "ROUTE" && reader.tokenType() == QXmlStreamReader::EndElement))
    {
        // No attributes
        reader.readNext();

        if (reader.name() == "LENGTH" && reader.isStartElement())
        {
            // Only one LENGTH element per route.
            QTime time;
            parseLength(reader, time, routeDistance);
        }
        else if (reader.name() == "POINT" && reader.isStartElement())
        {
            // Two POINT elements per route. One for start and dest points.
            // Start point has attribute uid="start" and dest has attribute uid="dest".
            if (reader.attributes().value("uid") == "start")
                routeStartPoint = parsePoint(reader);
            else if (reader.attributes().value("uid") == "dest")
                routeEndPoint = parsePoint(reader);
        }
        else if (reader.name() == "WALK" && reader.isStartElement())
        {
            routeSubRoute.append(parseWalk(reader));
        }
        else if (reader.name() == "LINE" && reader.isStartElement())
        {
            routeSubRoute.append(parseLine(reader));
        }
    }

    routeStartTime = routeStartPoint->departure_time;
    routeEndTime = routeEndPoint->arrival_time;
    RouteNew *route = new RouteNew(routeStartTime, routeEndTime, routeStartPoint, routeEndPoint, routeWalkingDistance, routeDistance, routeSubRoute);

    //qDebug() << "Route parsed.";

    return route;
}
Exemple #9
0
//auto, #000000, 78px
QSharedPointer<Value> CSSParser::parseValue(){
#ifdef CSS_DEBUG
    qDebug() << Q_FUNC_INFO;
#endif /* CSS_DEBUG */
    QChar c = peekChar();
    if (c.isDigit()) {
        return parseLength();
    } else if (c == '#') {
        return parseColor();
    } else {
//        QSharedPointer<KeywordValue> ret = QSharedPointer<KeywordValue>(new KeywordValue(parseIdentifier()));
        return QSharedPointer<KeywordValue>(new KeywordValue(parseIdentifier()));
    }
    qDebug() << Q_FUNC_INFO << "enter a dead end";

}
Exemple #10
0
int parseArgs(int argc,char *argv[]) {
  int len;
  int i;
  static const int pindex[5]={5,6,7,13,14};
  static const int vindex[5]={8,9,10,11,15};

  memset(&wavtool_args,0,sizeof(wavtool_args));

  if (argc <= 2) {
    return -1;
  }
  
  len = strlen(argv[1]);
  wavtool_args.outputfilename = (char *)malloc(sizeof(char)*(len+1));
  memset(wavtool_args.outputfilename,0,sizeof(char)*(len+1));
  strncpy(wavtool_args.outputfilename, argv[1], len);
  
  if (isFileExist(argv[2])) {
    len = strlen(argv[2]);
    wavtool_args.inputfilename = (char *)malloc(sizeof(char)*(len+1));
    memset(wavtool_args.inputfilename,0,sizeof(char)*(len+1));
    strncpy(wavtool_args.inputfilename, argv[2], len);
  }

  if (argc >= 4) {
    sscanf(argv[3],"%lf",&(wavtool_args.offset));
  }

  if (argc >= 5) {
    wavtool_args.length = parseLength(argv[4]);
  }

  if (argc >= 13) {
    sscanf(argv[12],"%lf",&(wavtool_args.ovr));
  }

  for (i=0; i<5; i++) {
    if (argc >= pindex[i]+1) {
      sscanf(argv[pindex[i]],"%lf",&(wavtool_args.p[i]));
    }
    if (argc >= vindex[i]+1) {
      sscanf(argv[vindex[i]],"%lf",&(wavtool_args.v[i]));
    }
  }
  return 0;
}
Exemple #11
0
void SimondConnector::messageReceived()
{
    waitFor(sizeof(qint32));
    qint32 code;

    *response >> code;
    qDebug() << "Message received: " << code;
    switch (code) {
    case Simond::VersionIncompatible:
        emit error(tr("Server version incompatible with client."));
        disconnectFromServer();
        break;
    case Simond::AuthenticationFailed:
        emit error(tr("Authentication failed. Please check the configured user name and password in the configuration."));
        disconnectFromServer();
        break;
    case Simond::LoginSuccessful:
        emit status(tr("Logged in"));
        break;
    case Simond::RecognitionReady:
        emit status(tr("Recognition ready; Activating..."));
        sendRequest(Simond::StartRecognition);
        break;
    case Simond::RecognitionStarted:
        emit status("Recognition activated");
        emit connectionState(Connected);
        break;
    case Simond::RecognitionError: {
        parseLength();
        QByteArray errorMessage, protocol;
        *response >> errorMessage;
        *response >> protocol;
        emit error(tr("Recognition reported error: ").arg(QString::fromUtf8(errorMessage)));
        disconnectFromServer();
        break;
    }
    case Simond::RecognitionWarning: {
        parseLength();
        QByteArray warningMessage;
        *response >> warningMessage;
        emit error(tr("Recognition reported warning: %1").arg(QString::fromUtf8(warningMessage)));
        break;
    }
    case Simond::RecognitionStopped:
        break; //nothing to do
    case Simond::RecognitionResult: {
        parseLength();

        qint8 sentenceCount;
        *response >> sentenceCount;
        RecognitionResultList recognitionResults;

        for (int i=0; i < sentenceCount; i++) {
          QByteArray word, sampa, samparaw;
          QList<float> confidenceScores;
          *response >> word;
          *response >> sampa;
          *response >> samparaw;
          *response >> confidenceScores;
          recognitionResults.append(RecognitionResult(QString::fromUtf8(word),
            QString::fromUtf8(sampa),
            QString::fromUtf8(samparaw),
            confidenceScores));
        }
        emit recognized(recognitionResults);
        break;
    }

    default:
        qDebug() << "Unhandled request: " << code;
    }
    if (socket->bytesAvailable())
        messageReceived();
}
Exemple #12
0
RouteLeg* parseLine(QXmlStreamReader &reader)
{
    //qDebug() << "Parsing LINE";

    double distance;
    QTime time;
    RoutePoint *startPoint, *endPoint;
    QList<RoutePoint*> midpoints;// = QList<RoutePoint*>();

    bool startFound = false;
    bool endFound = false;

    QXmlStreamAttributes attributes(reader.attributes());
    QString code = attributes.value("code").toString();
    int type = attributes.value("type").toString().toInt();

    while (!reader.atEnd() && !(reader.name() == "LINE" && reader.tokenType() == QXmlStreamReader::EndElement))
    {
        reader.readNext();

        if (reader.name() == "LENGTH" && reader.isStartElement())
        {
            // One LENGTH element in WALK.
            parseLength(reader, time, distance);
        }
        else if (reader.name() == "STOP" && reader.isStartElement())
        {
            // Multiple STOP elements may be found. No other LEG_TYPEs are possible. All but first and last will be appended to midpoints list.
            // If first one is not found yet, don't append point to list, but store it to startPoint.
            // If first one is found but last one is not, don't append to list, but store it to endPoint.
            // Else, append endPoint to list and store new one to endPoint.
            if (!startFound)
            {
                startPoint = parseStop(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseStop(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseStop(reader);
            }
        }
    }

    /* Types from reittiopas:
        Transport types:
        1 Helsinki/bus
        2 Helsinki/tram
        3 Espoo internal
        4 Vantaa internal
        5 Regional traffic
        6 Metro traffic
        7 Ferry
        8 U-lines
        9 Other local traffic
        10 Long-distance traffic
        11 Express
        12 VR local traffic
        13 VR long-distance traffic
        14 All
        21 Helsinki service lines
        22 Helsinki night traffic
        23 Espoo service lines
        24 Vantaa service lines
        25 Regional night traffic
        (types 9,10,11,13,14 are not used in the data)
*/
    RouteLeg* line = NULL;
    if (type == 6)
    {
        // Metro
        line = RouteLegGenerator::createLegSub(distance, time, startPoint, endPoint, midpoints);
    }
    else if (type == 2)
    {
        // Tram
        QString symbol = parseLineSymbol(code);
        line = RouteLegGenerator::createLegTram(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else if (type == 1 || type == 3 || type == 4 || type == 5 || type == 8 || type == 21 || type == 22 || type == 23 || type == 24 || type == 25)
    {
        // Bus
        QString symbol = parseLineSymbol(code);
        line = RouteLegGenerator::createLegBus(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else if (type == 7)
    {
        // Ferry
        line = RouteLegGenerator::createLegFerry(distance, time, startPoint, endPoint, midpoints);
    }
    else if (type == 12)
    {
        // Train
        QString symbol = parseLineSymbol(code);
        symbol = symbol.mid(1,1);
        line = RouteLegGenerator::createLegTrain(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else
        qDebug() << "Type mismatch (" << type << "!!!! Returning NULL!!!!";

    //qDebug() << "LINE parsed.";

    return line;
}
Exemple #13
0
RouteLeg* parseWalk(QXmlStreamReader &reader)
{
    //qDebug() << "Parsing WALK";

    double distance;
    QTime time;
    RoutePoint *startPoint, *endPoint;
    QList<RoutePoint*> midpoints;// = QList<RoutePoint*>();

    bool startFound = false;
    bool endFound = false;

    while (!reader.atEnd() && !(reader.name() == "WALK" && reader.tokenType() == QXmlStreamReader::EndElement))
    {
        reader.readNext();

        if (reader.name() == "LENGTH" && reader.isStartElement())
        {
            // One LENGTH element in WALK.
            parseLength(reader, time, distance);
        }
        else if (reader.name() == "POINT" && reader.isStartElement())
        {
            // Multiple POINT, MAPLOC or STOP elements may be found. All but first and last will be appended to midpoints list.
            // If first one is not found yet, don't append point to list, but store it to startPoint.
            // If first one is found but last one is not, don't append to list, but store it to endPoint.
            // Else, append endPoint to list and store new one to endPoint.
            if (!startFound)
            {
                startPoint = parsePoint(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parsePoint(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parsePoint(reader);
            }
        }
        else if (reader.name() == "MAPLOC" && reader.isStartElement())
        {
            // Read comments from above. POINT
            if (!startFound)
            {
                startPoint = parseMapLoc(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseMapLoc(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseMapLoc(reader);
            }
        }
        else if (reader.name() == "STOP" && reader.isStartElement())
        {
            // Read comments from above. POINT
            if (!startFound)
            {
                startPoint = parseStop(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseStop(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseStop(reader);
            }
        }
    }

    RouteLeg *walk = RouteLegGenerator::createLegWalk(distance, time, startPoint, endPoint, midpoints);

    //qDebug() << "WALK parsed.";

    return walk;
}
Exemple #14
0
Length StringImpl::toLength()
{
    return parseLength(m_data, m_length);
}
Exemple #15
0
bool esvg::RadialGradient::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
	// line must have a minimum size...
	//m_paint.strokeWidth = 1;
	if (_element.exist() == false) {
		return false;
	}
	
	// ---------------- get unique ID ----------------
	m_id = _element.attributes["id"];
	
	//parseTransform(_element);
	//parsePaintAttr(_element);
	
	// add the property of the parrent modifications ...
	m_transformMatrix *= _parentTrans;
	
	std::string contentX = _element.attributes["cx"];
	std::string contentY = _element.attributes["cy"];
	if (    contentX != ""
	     && contentY != "") {
		m_center.set(contentX, contentY);
	}
	contentX = _element.attributes["r"];
	if (contentX != "") {
		m_radius.set(contentX);
	}
	contentX = _element.attributes["fx"];
	contentY = _element.attributes["fy"];
	if (    contentX != ""
	     && contentY != "") {
		m_focal.set(contentX, contentY);
	}
	contentX = _element.attributes["gradientUnits"];
	if (contentX == "userSpaceOnUse") {
		m_unit = gradientUnits_userSpaceOnUse;
	} else {
		m_unit = gradientUnits_objectBoundingBox;
		if (    contentX.size() != 0
		     && contentX != "objectBoundingBox") {
			ESVG_ERROR("Parsing error of 'gradientUnits' ==> not suported value: '" << contentX << "' not in : {userSpaceOnUse/objectBoundingBox} use objectBoundingBox");
		}
	}
	contentX = _element.attributes["spreadMethod"];
	if (contentX == "reflect") {
		m_spread = spreadMethod_reflect;
	} else if (contentX == "repeat") {
		m_spread = spreadMethod_repeat;
	} else {
		m_spread = spreadMethod_pad;
		if (    contentX.size() != 0
		     && contentX != "pad") {
			ESVG_ERROR("Parsing error of 'spreadMethod' ==> not suported value: '" << contentX << "' not in : {reflect/repeate/pad} use pad");
		}
	}
	// note: xlink:href is incompatible with subNode "stop"
	m_href = _element.attributes["xlink:href"];
	if (m_href.size() != 0) {
		m_href = std::string(m_href.begin()+1, m_href.end());
	}
	// parse all sub node :
	for(auto it : _element.nodes) {
		exml::Element child = it.toElement();
		if (child.exist() == false) {
			// can be a comment ...
			continue;
		}
		if (child.getValue() == "stop") {
			float offset = 100;
			etk::Color<float,4> stopColor = etk::color::none;
			std::string content = child.attributes["offset"];
			if (content.size()!=0) {
				std::pair<float, enum esvg::distance> tmp = parseLength2(content);
				if (tmp.second == esvg::distance_pixel) {
					// special case ==> all time % then no type define ==> % in [0.0 .. 1.0]
					offset = tmp.first*100.0f;
				} else if (tmp.second != esvg::distance_pourcent) {
					ESVG_ERROR("offset : " << content << " res=" << tmp.first << "," << tmp.second << " Not support other than pourcent %");
				} else {
					offset = tmp.first;
				}
			}
			content = child.attributes["stop-color"];
			if (content.size()!=0) {
				stopColor = parseColor(content).first;
				ESVG_VERBOSE(" color : \"" << content << "\"  == > " << stopColor);
			}
			content = child.attributes["stop-opacity"];
			if (content.size()!=0) {
				float opacity = parseLength(content);
				opacity = std::avg(0.0f, opacity, 1.0f);
				stopColor.setA(opacity);
				ESVG_VERBOSE(" opacity : '" << content << "'  == > " << stopColor);
			}
			m_data.push_back(std::pair<float, etk::Color<float,4>>(offset, stopColor));
		} else {
			ESVG_ERROR("(l " << child.getPos() << ") node not suported : '" << child.getValue() << "' must be [stop]");
		}
	}
	if (m_data.size() != 0) {
		if (m_href != "") {
			ESVG_ERROR("(l " << _element.getPos() << ") node can not have an xlink:href element with sub node named: stop ==> removing href");
			m_href = "";
		}
	}
	return true;
}