Common::UString GFF3Struct::getString(const Common::UString &field, const Common::UString &def) const { const Field *f = getField(field); if (!f) return def; // Direct string if (f->type == kFieldTypeExoString) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readUint32LE(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } // ResRef, resource reference, a shorter string if (f->type == kFieldTypeResRef) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readByte(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } // LocString, a localized string if (f->type == kFieldTypeLocString) { LocString locString; getLocString(field, locString); return locString.getString(); } // Unsigned integer type, compose a string representation if ((f->type == kFieldTypeByte ) || (f->type == kFieldTypeUint16) || (f->type == kFieldTypeUint32) || (f->type == kFieldTypeUint64) || (f->type == kFieldTypeStrRef)) { return Common::composeString(getUint(field)); } // Signed integer type, compose a string representation if ((f->type == kFieldTypeChar ) || (f->type == kFieldTypeSint16) || (f->type == kFieldTypeSint32) || (f->type == kFieldTypeSint64)) { return Common::composeString(getSint(field)); } // Floating point type, compose a string representation if ((f->type == kFieldTypeFloat) || (f->type == kFieldTypeDouble)) { return Common::composeString(getDouble(field)); } // Vector, consisting of 3 floats if (f->type == kFieldTypeVector) { float x = 0.0, y = 0.0, z = 0.0; getVector(field, x, y, z); return Common::composeString(x) + "/" + Common::composeString(y) + "/" + Common::composeString(z); } // Orientation, consisting of 4 floats if (f->type == kFieldTypeOrientation) { float a = 0.0, b = 0.0, c = 0.0, d = 0.0; getOrientation(field, a, b, c, d); return Common::composeString(a) + "/" + Common::composeString(b) + "/" + Common::composeString(c) + "/" + Common::composeString(d); } throw Common::Exception("GFF3: Field is not a string(able) type"); }
Common::UString GFF3Struct::getString(const Common::UString &field, const Common::UString &def) const { const Field *f = getField(field); if (!f) return def; if (f->type == kFieldTypeExoString) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readUint32LE(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if (f->type == kFieldTypeResRef) { Common::SeekableReadStream &data = getData(*f); const uint32 length = data.readByte(); return Common::readStringFixed(data, Common::kEncodingASCII, length); } if (f->type == kFieldTypeLocString) { LocString locString; getLocString(field, locString); return locString.getString(); } if ((f->type == kFieldTypeByte ) || (f->type == kFieldTypeUint16) || (f->type == kFieldTypeUint32) || (f->type == kFieldTypeUint64) || (f->type == kFieldTypeStrRef)) { return Common::composeString(getUint(field)); } if ((f->type == kFieldTypeChar ) || (f->type == kFieldTypeSint16) || (f->type == kFieldTypeSint32) || (f->type == kFieldTypeSint64)) { return Common::composeString(getSint(field)); } if ((f->type == kFieldTypeFloat) || (f->type == kFieldTypeDouble)) { return Common::composeString(getDouble(field)); } if (f->type == kFieldTypeVector) { float x = 0.0, y = 0.0, z = 0.0; getVector(field, x, y, z); return Common::composeString(x) + "/" + Common::composeString(y) + "/" + Common::composeString(z); } if (f->type == kFieldTypeOrientation) { float a = 0.0, b = 0.0, c = 0.0, d = 0.0; getOrientation(field, a, b, c, d); return Common::composeString(a) + "/" + Common::composeString(b) + "/" + Common::composeString(c) + "/" + Common::composeString(d); } throw Common::Exception("GFF3: Field is not a string(able) type"); }