本文整理汇总了C++中IReader::readUTF方法的典型用法代码示例。如果您正苦于以下问题:C++ IReader::readUTF方法的具体用法?C++ IReader::readUTF怎么用?C++ IReader::readUTF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReader
的用法示例。
在下文中一共展示了IReader::readUTF方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: opaque
//.........这里部分代码省略.........
return false;
atts.set(attributeID, f);
len -= 4;
} else {
// float[] array = new float[len/4];
// for (int i=0; i<array.length; i++) {
// array[i] = in.readFloat();
// len-=4;
// }
// atts.set(attributeID, array);
}
break;
case IAttributes::INT:
if (len == 4) {
int i;
if (!reader.readInt(i))
return false;
atts.set(attributeID, i);
len -= 4;
} else {
// int[] array = new int[len/4];
// for (int i=0; i<array.length; i++) {
// array[i] = in.readInt();
// len-=4;
// }
// atts.set(attributeID, array);
}
break;
case IAttributes::LONG:
if (len == 8) {
int64 l;
if (!reader.readLong(l))
return false;
atts.set(attributeID, l);
len -= 8;
} else {
// long[] array = new long[len/8];
// for (int i=0; i<array.length; i++) {
// array[i] = in.readLong();
// len-=8;
// }
// atts.set(attributeID, array);
}
break;
case IAttributes::SHORT:
if (len == 2) {
short s;
if (!reader.readShort(s))
return false;
atts.set(attributeID, s);
len -= 2;
} else {
// short[] array = new short[len/2];
// for (int i=0; i<array.length; i++) {
// array[i] = in.readShort();
// len-=2;
// }
// atts.set(attributeID, array);
}
break;
case IAttributes::STRING: {
vector<wstring> vs;
while (len != 0) {
wstring s;
unsigned short utflen;
if (!reader.readUTF(s, utflen))
return false;
unsigned char b;
if (!reader.readByte(b))
return false; // skip NULL termination
vs.push_back(s);
len -= utflen + 2+ 1;
}
if (vs.size() == 1) {
atts.set(attributeID, vs[0]);
} else {
// String[] array = new String[vs.size()];
// array = (String[])vs.toArray(array);
// atts.set(attributeID, array);
}
}
break;
default:
cerr << endl << "ERROR No opaque handler for attributeID: "<< attributeID
<< " part of tagID: "<< tagID << endl;
return false;
}
if (debug) cout << " : Value";
if (len != 0) {
cerr << endl << "Skipping "<< len << " unused OPAQUE bytes..."<< endl;
while (len != 0) {
unsigned char b;
if (!reader.readByte(b))
return false;
len--;
}
}
return true;
}
示例2: parse
bool Parser::parse(IReader& reader, bool verbose) {
wchar_t entityBuf;
debug = verbose;
tagPage = 0;
attributePage = 0;
if (!reader.readByte(version))
return false;
if (version != 0x03)
return false;
if (debug) cout << " : Version";
if (!reader.readMultiByteInt(publicIdentifierId))
return false;
if (debug) cout << " : PublicIdentifierId";
unsigned int dtdIndex = 0;
if (publicIdentifierId == 0) {
if (!reader.readMultiByteInt(dtdIndex))
return false;
if (debug) cout << " : dtdIndex";
} else {
return false;
}
if (dtdIndex != 0)
return false;
if (!reader.readMultiByteInt(charSet))
return false;
if (charSet != 0x6a)
return false;
if (debug) cout << " : CharSet";
unsigned int len;
if (!reader.readMultiByteInt(len))
return false;
if (debug) cout << " : StringTable Len";
unsigned int offset = 0;
while (offset < len) {
wstring s;
unsigned short utflen;
if (!reader.readUTF(s, utflen))
return false;
unsigned char b;
if (!reader.readByte(b))
return false; // skip null termination
if (debug) cout << " : null termination";
reader.putStrT(offset, s);
offset += utflen + 2+ 1;
}
if (!contentHandler.startDocument())
return false;
if (publicIdentifierId == 0) {
wstring dtdPair;
if (!reader.getStrT(dtdIndex, dtdPair))
return false;
if (debug) cout << " : dtdPair";
size_t space = dtdPair.find(' ');
if (space == string::npos) {
cout << endl << "DTD specifier does not contain 'space'"<< endl;
exit(1);
}
wstring name = dtdPair.substr(0, space);
wstring dtd = dtdPair.substr(space+1);
istream* resolverStream = resolver.resolveEntity(name,L"" , dtd);
if (resolverStream != NULL) {
// FIXME, use the resolver stream
cout << endl << "Entity Resolver NOT Used." << endl;
}
}
unsigned char id;
while (reader.readByte(id)) {
switch (id) {
case WBXML::SWITCH_PAGE:
if (debug) cout << " : Switch Page";
if (!reader.readByte(tagPage)) return false;
if (debug) cout << " : TagPage: " << (unsigned int)tagPage;
break;
case WBXML::END: {
unsigned int tagID;
if (stack.empty()) return false;
tagID = stack.top();
stack.pop();
if (debug) cout << " : </" << tagHandler.getTag(tagID) << ">";
if (!contentHandler.endElement(tagID)) return false;
break;
}
case WBXML::ENTITY:
if (debug) cout << " : Entity";
if (!reader.readMultiByteInt((unsigned int&)entityBuf)) return false;
if (debug) cout << " : " << entityBuf;
if (!contentHandler.characters(&entityBuf, 0, 1)) return false;
break;
//.........这里部分代码省略.........