bool DecimalFormatRenderer::FormatNumber( String &sString, String &sScale, String &sDecSeparator ) { StartTrace(DecimalFormatRenderer.FormatNumber); String strTmp(sString); String strToken, strNumber, strDecPlaces; StringTokenizer tok(strTmp, sDecSeparator[0L]); if ( tok(strToken) ) { Trace("current token [" << strToken << "]"); strNumber = strToken; } else { strNumber = "0"; } if ( tok(strToken) ) { Trace("current token [" << strToken << "]"); strDecPlaces = strToken; } else { strDecPlaces = ""; } if (sScale.AsLong(0L) > 0L) { InsertFiller( sScale, strDecPlaces ); Trace("decimal [" << strDecPlaces << "] scale [" << sScale.AsLong(0L) << "]"); sString = strNumber << sDecSeparator << strDecPlaces.SubString(0L, sScale.AsLong(0L)); } else { sString = strNumber; Trace("result scale = 0 [" << sString << "]"); } return true; }
void DecimalFormatRenderer::InsertFiller(String &sScale, String &strDecPlaces ) { StartTrace(DecimalFormatRenderer.InsertFiller); for ( long lIdx = strDecPlaces.Length(); lIdx < sScale.AsLong(0L) ; lIdx++) { strDecPlaces.Append("0"); Trace("scale [ " << strDecPlaces << "] index [ " << lIdx << " ]"); } }
bool SelectBoxRenderer::IsMultipleSelect(Context &context, const ROAnything &config) { StartTrace(SelectBoxRenderer.IsMultipleSelect); String str; if (config.IsDefined("Multiple")) { RenderOnString(str, context, config["Multiple"]); } return (str.AsLong(0L) == 1L); }
void SelectBoxRenderer::RenderOptions(std::ostream &reply, Context &context, const ROAnything &config) { // render SIZE argument reply << " size=\""; // length of list (default 1 see HTML-Spec.) String str; if (config.IsDefined("Size")) { RenderOnString(str, context, config["Size"]); } reply << str.AsLong(1L); reply << "\""; if (IsMultipleSelect(context, config)) { reply << " multiple"; } FieldRenderer::RenderOptions(reply, context, config); }
void FormattedStringRenderer::RenderAll(std::ostream &reply, Context &c, const ROAnything &config) { StartTrace(FormattedStringRenderer.RenderAll); TraceAny(config, "config"); String align, value, filler; long nSpaces = 4; ROAnything roaSlotConfig; if (config.LookupPath(roaSlotConfig, "Value")) { RenderOnString(value, c, roaSlotConfig); } else { reply << "Error in FormattedStringRenderer::RenderAll, Value not defined"; return; } Trace("Value: [" << value << "]"); if (config.LookupPath(roaSlotConfig, "Align")) { RenderOnString(align, c, roaSlotConfig); } else { align = "left"; } Trace("Align: [" << align << "]"); if (config.LookupPath(roaSlotConfig, "Filler")) { RenderOnString(filler, c, roaSlotConfig); } else { filler = " "; } Trace("Filler: [" << filler << "]"); long valueLen = getStringLength(value); long width = valueLen; if (config.LookupPath(roaSlotConfig, "Width")) { String sWidth; RenderOnString(sWidth, c, roaSlotConfig); width = sWidth.AsLong(valueLen); } Trace("Width: " << width); if (config.LookupPath(roaSlotConfig, "SpacesForTab")) { String sWidth; RenderOnString(sWidth, c, roaSlotConfig); nSpaces = sWidth.AsLong(nSpaces); } Trace("SpacesForTab: " << nSpaces); String result(128); long lLeftFill = 0, lRightFill = 0; // string is longer than field width, trim string if ( valueLen > width ) { valueLen = getStringLength(trim(value, width )); } else { if ( align.IsEqual("right") ) { lLeftFill = width - valueLen; } else if ( align.IsEqual("center") ) { lLeftFill = ( width - valueLen ) / 2L; lRightFill = width - valueLen - lLeftFill; } else { // default: left alignment lRightFill = width - valueLen; } } Trace("LeftFills: " << lLeftFill << ", RightFill : " << lRightFill ); for ( long iL = 0; iL < lLeftFill; ++iL) { result << filler; } std::for_each(value.begin(), value.end(), whitespaceReplacer(result, filler, nSpaces)); for ( long iR = 0; iR < lRightFill; ++iR ) { result << filler; } Trace("Rendered Value: [" << result << "]"); reply << result; }