Ejemplo n.º 1
0
bool StocksUpdateFromUDF(const UniversalDataFormat& udf)
{
    StocksPrefs& prefs = GetPreferences()->stocksPrefs;
    StocksPortfolio& p = prefs.portfolio(prefs.currentPortfolio);
    ulong_t len = udf.getItemsCount();
    assert(len == p.size()); 
    for (ulong_t i = 0; i < len; ++i)
    {
        StocksEntry& e = p.entry(i);
        assert(udf.getItemElementsCount(i) >= 2);
        
        free(e.url);
        e.url = StringCopy(udf.getItemData(i, stocksListItemUrlIndex));
        if (NULL == e.url)
            return false;
            
        const char_t* symbol = udf.getItemText(i, stocksListItemSymbolIndex);

        if (equalsIgnoreCase(symbol, e.symbol))
        {
            assert(stocksListElementsCount == udf.getItemElementsCount(i));
            e.status = e.statusReady;
            const char* trade = udf.getItemData(i, stocksListItemTradeIndex);
            const char* change = udf.getItemData(i, stocksListItemChangeIndex);
            const char* percent = udf.getItemData(i, stocksListItemPercentChangeIndex);
            if (errNone != numericValue(trade, -1, e.trade))
                return false;
            if (errNone != numericValue(change, -1, e.change))
                return false;
            ulong_t len = Len(percent);
            if (0 == len || '%' != percent[len - 1])
                return false;
            if (errNone != numericValue(percent, len - 1, e.percentChange))
                return false; 
        } 
        else if (equalsIgnoreCase(symbol, _T("?")))
        {
            assert(stocksListNotFoundElementsCount == udf.getItemElementsCount(i));
            e.status = e.statusAmbiguous;
        }
        else
        {
            assert(stocksListNotFoundElementsCount == udf.getItemElementsCount(i));
            free(e.data);
            e.data = StringCopy(symbol);
            if (NULL == e.data)
                return false;
            e.status = e.statusChanged; 
        }
    }  
    return true;
}
Ejemplo n.º 2
0
void DBNumberEdit::setValue(const QVariant &value)
{
	bool ok;
	double v = value.toDouble(&ok);
	double orig = numericValue();
	if ( ok && v != orig ) {
		setNumericValue(value.toDouble());
	}
}
Ejemplo n.º 3
0
double postfix (String exp) {
	int i, l = strlen(exp);
	TSNODE_p_t stack = NULL;
	
	TNODE_p_t root = NULL;
	
	for (i = 0; i < l; ++i) {
		char z = *(exp + i);
		
		if (isNumber(z)) {
			String str = initString;
			snprintf(str, SIZE, "%d", numericValue(z));
			root = initTNode(str);
			root->type = TYPE_OPERAND;
			push(&stack, root);
		}
			
		else if (isAlphabet(z)) {
			double numz;
			printf("\n\tEnter the value of '%c': ", z);
			scanf(" %lf", &numz);
			String str = initString;
			snprintf(str, SIZE, "%lf", numz);
			root = initTNode(str);
			root->type = TYPE_OPERAND;
			push(&stack, root);
		}
		
		else if (isOperator(z)) {
			TNODE_p_t b = pop(&stack);
			TNODE_p_t a = pop(&stack);
			String str = initString;
			snprintf(str, SIZE, "%c", z);
			root = initTNode(str);
			root->right = b;
			root->left = a;
			root->type = TYPE_OPERATOR;
			push(&stack, root);
		}
	
	}
	
	root = pop(&stack);
	
	return evaulate(root);
	
}
Ejemplo n.º 4
0
static status_t validateAddress(const NarrowString& origAddress, NarrowString& validAddress, ushort_t& port)
{
    NarrowString::size_type pos = origAddress.find(':', 1);
    if (origAddress.npos == pos)
        return netErrParamErr;
    
    ushort_t portLength = origAddress.length() - pos - 1;
    if (portLength>0)
    {
        long value=0;
        status_t error = numericValue(origAddress.data()+pos+1, origAddress.data()+pos+1+portLength, value);
        if ((errNone != error) || (value > ushort_t(-1)))
            return netErrParamErr;

        port = ushort_t(value);
    }

    if (0 == port)
        return netErrParamErr;        

    validAddress.assign(origAddress, 0, pos);
    return errNone;
}
void CSSParserToken::serialize(StringBuilder& builder) const
{
    // This is currently only used for @supports CSSOM. To keep our implementation
    // simple we handle some of the edge cases incorrectly (see comments below).
    switch (type()) {
    case IdentToken:
        serializeIdentifier(value(), builder);
        break;
    case FunctionToken:
        serializeIdentifier(value(), builder);
        return builder.append('(');
    case AtKeywordToken:
        builder.append('@');
        serializeIdentifier(value(), builder);
        break;
    case HashToken:
        // This will always serialize as a hash-token with 'id' type instead of
        // preserving the type of the input.
        builder.append('#');
        serializeIdentifier(value(), builder);
        break;
    case UrlToken:
        builder.append("url(");
        serializeIdentifier(value(), builder);
        return builder.append(")");
    case DelimiterToken:
        if (delimiter() == '\\')
            return builder.append("\\\n");
        return builder.append(delimiter());
    case NumberToken:
        // These won't properly preserve the NumericValueType flag
        return builder.appendNumber(numericValue());
    case PercentageToken:
        builder.appendNumber(numericValue());
        return builder.append('%');
    case DimensionToken:
        // This will incorrectly serialize e.g. 4e3e2 as 4000e2
        builder.appendNumber(numericValue());
        serializeIdentifier(value(), builder);
        break;
    case UnicodeRangeToken:
        return builder.append(String::format("U+%X-%X", unicodeRangeStart(), unicodeRangeEnd()));
    case StringToken:
        return serializeString(value(), builder);

    case IncludeMatchToken:
        return builder.append("~=");
    case DashMatchToken:
        return builder.append("|=");
    case PrefixMatchToken:
        return builder.append("^=");
    case SuffixMatchToken:
        return builder.append("$=");
    case SubstringMatchToken:
        return builder.append("*=");
    case ColumnToken:
        return builder.append("||");
    case CDOToken:
        return builder.append("<!--");
    case CDCToken:
        return builder.append("-->");
    case BadStringToken:
        return builder.append("'\n");
    case BadUrlToken:
        return builder.append("url(()");
    case WhitespaceToken:
        return builder.append(' ');
    case ColonToken:
        return builder.append(':');
    case SemicolonToken:
        return builder.append(';');
    case CommaToken:
        return builder.append(',');
    case LeftParenthesisToken:
        return builder.append('(');
    case RightParenthesisToken:
        return builder.append(')');
    case LeftBracketToken:
        return builder.append('[');
    case RightBracketToken:
        return builder.append(']');
    case LeftBraceToken:
        return builder.append('{');
    case RightBraceToken:
        return builder.append('}');

    case EOFToken:
    case CommentToken:
        ASSERT_NOT_REACHED();
        return;
    }
}
Ejemplo n.º 6
0
/* static */ PRInt32
nsMathMLFrame::MapAttributesIntoCSS(nsPresContext* aPresContext,
                                    nsIContent*     aContent)
{
  // normal case, quick return if there are no attributes
  NS_ASSERTION(aContent, "null arg");
  PRUint32 attrCount = 0;
  if (aContent)
    attrCount = aContent->GetAttrCount();
  if (!attrCount)
    return 0;

  // need to initialize here -- i.e., after registering nsMathMLAtoms
  static const nsCSSMapping
  kCSSMappingTable[] = {
    {kMathMLversion2, nsMathMLAtoms::mathcolor_,      "color:"},
    {kMathMLversion1, nsMathMLAtoms::color_,          "color:"},
    {kMathMLversion2, nsMathMLAtoms::mathsize_,       "font-size:"},
    {kMathMLversion1, nsMathMLAtoms::fontsize_,       "font-size:"},
    {kMathMLversion1, nsMathMLAtoms::fontfamily_,     "font-family:"},
    {kMathMLversion2, nsMathMLAtoms::mathbackground_, "background-color:"},
    {kMathMLversion1, nsMathMLAtoms::background_,     "background-color:"},
    {0, nsnull, nsnull}
  };

  nsCOMPtr<nsIDocument> doc;
  nsCOMPtr<nsIStyleSheet> sheet;
  nsCOMPtr<nsICSSStyleSheet> cssSheet;
  nsCOMPtr<nsIDOMCSSStyleSheet> domSheet;

  PRInt32 nameSpaceID;
  nsCOMPtr<nsIAtom> prefix;
  nsCOMPtr<nsIAtom> attrAtom;
  PRInt32 ruleCount = 0;
  for (PRUint32 i = 0; i < attrCount; ++i) {
    aContent->GetAttrNameAt(i, &nameSpaceID,
                            getter_AddRefs(attrAtom),
                            getter_AddRefs(prefix));

    // lookup the equivalent CSS property
    const nsCSSMapping* map = kCSSMappingTable;
    while (map->attrAtom && map->attrAtom != attrAtom)
      ++map;
    if (!map->attrAtom)
      continue;
    nsAutoString cssProperty(NS_ConvertASCIItoUCS2(map->cssProperty));

    nsAutoString attrValue;
    aContent->GetAttr(nameSpaceID, attrAtom, attrValue);
    if (attrValue.IsEmpty())
      continue;
    nsAutoString escapedAttrValue;
    nsStyleUtil::EscapeCSSString(attrValue, escapedAttrValue);

    // don't add rules that are already in mathml.css
    // (this will also clean up whitespace before units - see bug 125303)
    if (attrAtom == nsMathMLAtoms::fontsize_ || attrAtom == nsMathMLAtoms::mathsize_) {
      nsCSSValue cssValue;
      nsAutoString numericValue(attrValue);
      if (!ParseNumericValue(numericValue, cssValue))
        continue;
      // on exit, ParseNumericValue also returns a nicer string
      // in which the whitespace before the unit is cleaned up 
      cssProperty.Append(numericValue);
    }
    else
      cssProperty.Append(attrValue);

    nsAutoString attrName;
    attrAtom->ToString(attrName);

    // make a style rule that maps to the equivalent CSS property
    nsAutoString cssRule;
    cssRule.Assign(NS_LITERAL_STRING("[")  + attrName +
                   NS_LITERAL_STRING("='") + escapedAttrValue +
                   NS_LITERAL_STRING("']{") + cssProperty + NS_LITERAL_STRING("}"));

    if (!sheet) {
      // first time... we do this to defer the lookup up to the
      // point where we encounter attributes that actually matter
      doc = aContent->GetDocument();
      if (!doc) 
        return 0;
      GetMathMLAttributeStyleSheet(aPresContext, getter_AddRefs(sheet));
      if (!sheet)
        return 0;
      // by construction, these cannot be null at this point
      cssSheet = do_QueryInterface(sheet);
      domSheet = do_QueryInterface(sheet);
      NS_ASSERTION(cssSheet && domSheet, "unexpected null pointers");
      // we will keep the sheet orphan as we populate it. This way,
      // observers of the document won't be notified and we avoid any troubles
      // that may come from reconstructing the frame tree. Our rules only need
      // a re-resolve of style data and a reflow, not a reconstruct-all...
      sheet->SetOwningDocument(nsnull);
    }

    // check for duplicate, if a similar rule is already there, don't bother to add another one
    nsAutoString selector;
    selector.Assign(NS_LITERAL_STRING("*[") + attrName +
                    NS_LITERAL_STRING("=\"") + escapedAttrValue +
                    NS_LITERAL_STRING("\"]"));
    PRInt32 k, count;
    cssSheet->StyleRuleCount(count);
    for (k = 0; k < count; ++k) {
      nsAutoString tmpSelector;
      nsCOMPtr<nsICSSRule> tmpRule;
      cssSheet->GetStyleRuleAt(k, *getter_AddRefs(tmpRule));
      nsCOMPtr<nsICSSStyleRule> tmpStyleRule = do_QueryInterface(tmpRule);
      if (tmpStyleRule) {
        tmpStyleRule->GetSelectorText(tmpSelector);
        if (tmpSelector.Equals(selector)) {
          k = -1;
          break;
        }
      }
    }
    if (k >= 0) {
      // insert the rule (note: when the sheet already has @namespace and
      // friends, insert after them, e.g., at the end, otherwise it won't work)
      // For MathML 2, insert at the end to give it precedence
      PRInt32 pos = (map->compatibility == kMathMLversion2) ? count : 1;
      PRUint32 index;
      domSheet->InsertRule(cssRule, pos, &index);
      ++ruleCount;
    }
  }
  // restore the sheet to its owner
  if (sheet) {
    sheet->SetOwningDocument(doc);
  }

  return ruleCount;
}
Ejemplo n.º 7
0
status_t parseUniversalDataFormatTextLine(const char* line, ulong_t len, UniversalDataFormat& out, ulong_t& lineNo, ulong_t& controlDataLength)
{
    long resultLong;
    const char* data = line; 
    UniversalDataFormat::Vector_t vec;
    ErrTry {
        if (lineNo == 0)
        {
            if (errNone != numericValue(data, data + len, resultLong))
                ErrReturn(SocketConnection::errResponseMalformed);

            out.setHeaderSize(resultLong);
        }
        else if (lineNo <= out.headerSize_)
        {
            //read values from vector
            const char* dataOffset = data;
            while (data + len > dataOffset)
            {
                const char* dataOffsetEnd = dataOffset;
                while (dataOffsetEnd < data + len && dataOffsetEnd[0] != ' ')
                    dataOffsetEnd++;
                    
                if (errNone != numericValue(dataOffset, dataOffsetEnd, resultLong))
		          ErrReturn(SocketConnection::errResponseMalformed);

                vec.push_back(resultLong);
                controlDataLength += resultLong + 1;
                dataOffset = dataOffsetEnd + 1;
            }
            out.header_.push_back(vec);
        }
        else
        {
            if (lineNo == out.headerSize_ + 1)
            {
                free(out.data_);
                out.dataLen_ = 0; 
                out.data_ = StringCopyN(line, len);
                if (NULL == out.data_)
					ErrReturn(memErrNotEnoughSpace);
						
				out.dataLen_ = len; 
            } 
            else
            {
				out.data_ = StrAppend(out.data_, out.dataLen_, "\n", 1);
				if (NULL == out.data_)
					ErrReturn(memErrNotEnoughSpace);
				
				++out.dataLen_;
				out.data_ = StrAppend(out.data_, out.dataLen_, line, len);
				if (NULL == out.data_)
					ErrReturn(memErrNotEnoughSpace);
					
				out.dataLen_ += len;
            }
        }
        lineNo++;
    }
    ErrCatch (ex) {
        return ex;
    } ErrEndCatch
    return errNone;
}
Ejemplo n.º 8
0
QVariant DBNumberEdit::value()
{
	QVariant v(numericValue());
	return v;
}
Ejemplo n.º 9
0
bool CSSParserToken::isValidNumericValue() const
{
    return isValidNumericValue(numericValue());
}