📄 stafdatatypes.cpp
字号:
return kSTAFOk;}STAFRC_t STAFObjectIsReference(STAFObject_t object, unsigned int *isRef){ if (object == 0) return kSTAFInvalidObject; if (isRef == 0) return kSTAFInvalidParm; *isRef = object->isRef ? 1 : 0; return kSTAFOk;}STAFRC_t STAFObjectGetStringValue(STAFObject_t object, STAFString_t *pString){ if (object == 0) return kSTAFInvalidObject; if (pString == 0) return kSTAFInvalidParm; if (object->type == kSTAFNoneObject) { static STAFString sNoneString("<None>"); STAFStringConstructCopy(pString, sNoneString.getImpl(), 0); } else if (object->type == kSTAFScalarStringObject) { STAFStringConstructCopy(pString, object->scalarStringValue->getImpl(), 0); } else if (object->type == kSTAFListObject) { unsigned int size = 0; STAFObjectGetSize(object, &size); STAFString sListString = STAFString("<List>[") + size + "]"; STAFStringConstructCopy(pString, sListString.getImpl(), 0); } else if (object->type == kSTAFMapObject) { static STAFString sMapClassKey("staf-map-class-name"); unsigned int size = 0; STAFObjectGetSize(object, &size); STAFObjectMap::iterator iter = object->mapValue->find(sMapClassKey); if (iter != object->mapValue->end()) { STAFString_t mapClassNameT = 0; STAFObjectGetStringValue(iter->second, &mapClassNameT); STAFString sMapString = STAFString("<Map:") + STAFString(mapClassNameT, STAFString::kShallow) + ">[" + size + "]"; STAFStringConstructCopy(pString, sMapString.getImpl(), 0); } else { STAFString sMapString = STAFString("<Map>[") + size + "]"; STAFStringConstructCopy(pString, sMapString.getImpl(), 0); } } else if (object->type == kSTAFMarshallingContextObject) { unsigned int size = 0; STAFObjectGetSize(object, &size); STAFString sContextString = STAFString("<MarshalingContext>[") + size + "]"; STAFStringConstructCopy(pString, sContextString.getImpl(), 0); } else *pString = STAFString("<Unknown>").adoptImpl(); return kSTAFOk;}STAFString ISTAFQuoteString(const STAFString &input){ static STAFString sSingleQuote(kUTF8_SQUOTE); static STAFString sDoubleQuote(kUTF8_DQUOTE); static STAFString sEscapedSingleQuote("\\'"); if (input.find(sSingleQuote) == STAFString::kNPos) return STAFString(sSingleQuote) + input + STAFString(sSingleQuote); if (input.find(sDoubleQuote) == STAFString::kNPos) return STAFString(sDoubleQuote) + input + STAFString(sDoubleQuote); return STAFString(sSingleQuote) + input.replace(sSingleQuote, sEscapedSingleQuote) + STAFString(sSingleQuote);}STAFString ISTAFGetLineSep(){ struct STAFConfigInfo configInfo = { 0 }; STAFUtilGetConfigInfo(&configInfo, 0, 0); return configInfo.lineSeparator;}void ISTAFObjectGetFormattedStringValue(STAFString &output, STAFObjectPtr &objPtr, STAFObjectPtr &context, unsigned int indentLevel){ static unsigned int sIndentDelta = 2; static STAFString sSpaces(" " " "); static STAFString sListIndent("["); static STAFString sListOutdent("]"); static STAFString sMapIndent("{"); static STAFString sMapOutdent("}"); static STAFString sEntrySeparator(""); static STAFString sMapKeySeparator(": "); static STAFString sKey("key"); static STAFString sMapClassKey("staf-map-class-name"); static STAFString sDisplayName("display-name"); static STAFString sLineSep = ISTAFGetLineSep(); switch (objPtr->type()) { case kSTAFListObject: { output += sListIndent; ++indentLevel; if (objPtr->size() > 0) output += sLineSep; // Print out each object // Get the size of the list and create an array with that size. // Add a string representing each element in the list to the array // and then join the strings in the array. // Using an array and then doing a join is done for performance // reasons as it's faster than concatenating strings using +=. unsigned int size = objPtr->size(); STAFString *stringArray = new STAFString[size]; unsigned int i = 0; for (STAFObjectIteratorPtr iterPtr = objPtr->iterate(); iterPtr->hasNext();) { STAFString entryOutput; STAFObjectPtr thisObj = iterPtr->next(); if ((thisObj->type() == kSTAFListObject) || (thisObj->type() == kSTAFMapObject) || (thisObj->type() == kSTAFMarshallingContextObject)) { entryOutput += sSpaces.subString(0, indentLevel * sIndentDelta); ISTAFObjectGetFormattedStringValue( entryOutput, thisObj, context, indentLevel); } else { entryOutput += sSpaces.subString(0, indentLevel * sIndentDelta); if (thisObj->type() == kSTAFNoneObject) entryOutput += thisObj->asString(); else entryOutput += thisObj->asString(); } if (iterPtr->hasNext()) entryOutput += sEntrySeparator; entryOutput += sLineSep; stringArray[i++].replaceImpl(entryOutput.adoptImpl()); } output.join(stringArray, size); delete [] stringArray; --indentLevel; if (objPtr->size() > 0) output += sSpaces.subString(0, indentLevel * sIndentDelta); output += sListOutdent; break; } case kSTAFMapObject: { output += sMapIndent; ++indentLevel; if (objPtr->size() > 0) output += sLineSep; // Check if the map object has a map class key and if the context // is valid and contains a map class definition for this map class. // If not, treat as a plain map class. if (objPtr->hasKey(sMapClassKey) && context && (context->type() == kSTAFMarshallingContextObject) && context->hasMapClassDefinition(objPtr->get(sMapClassKey)->asString())) { // Map object has a map class definition in the context STAFMapClassDefinitionPtr mapClass = context->getMapClassDefinition( objPtr->get(sMapClassKey)->asString()); // Determine maximum key length STAFObjectIteratorPtr iterPtr; unsigned int maxKeyLength = 0; unsigned int size = 0; // Number of keys for (iterPtr = mapClass->keyIterator(); iterPtr->hasNext();) { size++; STAFObjectPtr theKey = iterPtr->next(); STAFString theKeyString; if (theKey->hasKey(sDisplayName)) theKeyString = theKey->get(sDisplayName)->asString(); else theKeyString = theKey->get(sKey)->asString(); if (theKeyString.length(STAFString::kChar) > maxKeyLength) maxKeyLength = theKeyString.length(STAFString::kChar); } // Now print each object in the map // Get the size of the map and create an array with that size. // Add a string representing each element in the map to the array // and then join the strings in the array. // Using an array and then doing a join is done for performance // reasons as it's faster than concatenating strings using +=. STAFString *stringArray = new STAFString[size]; unsigned int i = 0; for (iterPtr = mapClass->keyIterator(); iterPtr->hasNext();) { STAFObjectPtr theKey = iterPtr->next(); STAFString theKeyString; if (theKey->hasKey(sDisplayName)) theKeyString = theKey->get(sDisplayName)->asString(); else theKeyString = theKey->get(sKey)->asString(); STAFString entryOutput = sSpaces.subString( 0, indentLevel * sIndentDelta); entryOutput += theKeyString; entryOutput += sSpaces.subString(0, maxKeyLength - theKeyString.length(STAFString::kChar)); entryOutput += sMapKeySeparator; STAFObjectPtr thisObj = objPtr->get(theKey->get(sKey)->asString()); if ((thisObj->type() == kSTAFListObject) || (thisObj->type() == kSTAFMapObject) || (thisObj->type() == kSTAFMarshallingContextObject)) { ISTAFObjectGetFormattedStringValue( entryOutput, thisObj, context, indentLevel); } else if (thisObj->type() == kSTAFNoneObject) { entryOutput += thisObj->asString(); } else { entryOutput += thisObj->asString(); } if (iterPtr->hasNext()) entryOutput += sEntrySeparator; entryOutput += sLineSep; stringArray[i++].replaceImpl(entryOutput.adoptImpl()); } output.join(stringArray, size); delete [] stringArray; } else { // The map does not have a map class key or the map class // definition is not provided in the context // Determine maximum key length STAFObjectIteratorPtr iterPtr; unsigned int maxKeyLength = 0; for (iterPtr = objPtr->keyIterator(); iterPtr->hasNext();) { STAFString theKeyString = iterPtr->next()->asString(); if (theKeyString.length(STAFString::kChar) > maxKeyLength) maxKeyLength = theKeyString.length(STAFString::kChar); } // Now print each object in the map // Get the size of the map and create an array with that size. // Add a string representing each element in the map to the array // and then join the strings in the array. // Using an array and then doing a join is done for performance // reasons as it's faster than concatenating strings using +=. unsigned int size = objPtr->size(); STAFString *stringArray = new STAFString[size]; unsigned int i = 0; for (iterPtr = objPtr->keyIterator(); iterPtr->hasNext();) { STAFString theKeyString = iterPtr->next()->asString(); STAFString entryOutput = sSpaces.subString( 0, indentLevel * sIndentDelta); entryOutput += theKeyString; entryOutput += sSpaces.subString( 0, maxKeyLength - theKeyString.length(STAFString::kChar)); entryOutput += sMapKeySeparator; STAFObjectPtr thisObj = objPtr->get(theKeyString); if ((thisObj->type() == kSTAFListObject) || (thisObj->type() == kSTAFMapObject) || (thisObj->type() == kSTAFMarshallingContextObject)) { ISTAFObjectGetFormattedStringValue( entryOutput, thisObj, context, indentLevel); } else if (thisObj->type() == kSTAFNoneObject) { entryOutput += thisObj->asString(); } else { entryOutput += thisObj->asString(); } if (iterPtr->hasNext()) entryOutput += sEntrySeparator; entryOutput += sLineSep; stringArray[i++].replaceImpl(entryOutput.adoptImpl()); } output.join(stringArray, size); delete [] stringArray; } --indentLevel; if (objPtr->size() > 0) output += sSpaces.subString(0, indentLevel * sIndentDelta); output += sMapOutdent; break; } case kSTAFMarshallingContextObject: { STAFObjectPtr thisObj = objPtr->getRootObject(); ISTAFObjectGetFormattedStringValue(output, thisObj, objPtr, indentLevel); break; } default: { output += sSpaces.subString(0, indentLevel * sIndentDelta); output += objPtr->asString(); break; } }}STAFRC_t STAFObjectGetFormattedStringValue(STAFObject_t object, STAFString_t *pString, unsigned int flags){ if (object == 0) return kSTAFInvalidObject; if (pString == 0) return kSTAFInvalidParm; if (object->type == kSTAFNoneObject) { static STAFString sNoneString("<None>"); STAFStringConstructCopy(pString, sNoneString.getImpl(), 0); } else if (object->type == kSTAFScalarStringObject) { STAFStringConstructCopy(pString, object->scalarStringValue->getImpl(), 0); } else { STAFObjectPtr theObj = STAFObject::createReference(object); STAFObjectPtr context = STAFObject::createNone(); STAFString output; ISTAFObjectGetFormattedStringValue(output, theObj, context, 0); *pString = output.adoptImpl(); } return kSTAFOk;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -