in src/cas/xmiwriter.cpp [428:574]
string XmiWriter::arrayToString(FeatureStructure const & fs, char const * tag) {
stringstream str;
int typecode = internal::FSPromoter::demoteType(fs.getType());
switch (typecode) {
case internal::gs_tyIntArrayType: {
IntArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
str << arrayfs.get(i);
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyFloatArrayType: {
FloatArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
str << arrayfs.get(i);
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyBooleanArrayType: {
BooleanArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
if (arrayfs.get(i)) {
str << "true";
} else {
str << "false";
}
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyByteArrayType: {
ByteArrayFS arrayfs(fs);
size_t n = arrayfs.size();
char * out = new char[3];
memset(out,0,3);
for (size_t i=0; i < n;i++) {
sprintf(out,"%02X",0xFF & arrayfs.get(i));
//printf ("itoahexadecimal: %d %d\n",i, arrayfs.get(i));
str << out[0] << out[1];
}
delete[] out;
break;
}
case internal::gs_tyShortArrayType: {
ShortArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
str << arrayfs.get(i);
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyLongArrayType: {
LongArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
str << arrayfs.get(i);
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyDoubleArrayType: {
DoubleArrayFS arrayfs(fs);
size_t n = arrayfs.size();
for (size_t i=0; i < n;i++) {
str << arrayfs.get(i);
if (i+1 < n) {
str << " ";
}
}
break;
}
case internal::gs_tyFSArrayType: {
ArrayFS arrayfs(fs);
size_t size = arrayfs.size();
vector<XmiArrayElement*> * ootsList = NULL;
if (this->sharedData != NULL) {
ootsList = this->sharedData->getOutOfTypeSystemArrayElements(internal::FSPromoter::demoteFS(arrayfs));
}
size_t ootsIndex = 0;
for (size_t j=0; j < size; j++) {
int xmiId = getXmiId(uima::internal::FSPromoter::demoteFS(arrayfs.get(j)));//convert to xmiid; 0 if not set
if (xmiId == 0) { //if 0 check if its an Oots FS
// However, this null array element might have been a reference to an
//out-of-typesystem FS, so check the ootsArrayElementsList
if (ootsList != NULL) {
while (ootsIndex < ootsList->size()) {
XmiArrayElement * arel = ootsList->at(ootsIndex++);
if (arel->index == j) {
str << arel->xmiId;
break;
}
}
}
} else {
str << xmiId;
}
if (j+1 < size) {
str << " ";
}
}
break;
}
case internal::gs_tyStringArrayType: {
StringArrayFS arrayfs(fs);
size_t n = arrayfs.size();
icu::UnicodeString ustr;
for (size_t i=0; i < n;i++) {
ustr.setTo("");
normalize( arrayfs.get(i), ustr );
str << "<" << tag << ">" << ustr << "</" << tag << ">";
}
break;
}
default: {
cerr << "arrayToString() type not supported " << typecode << endl;
ErrorInfo errInfo;
errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
msg.addParam("arrayToString() type not supported.");
msg.addParam(typecode);
errInfo.setMessage(msg);
errInfo.setSeverity(ErrorInfo::unrecoverable);
ExcIllFormedInputError exc(errInfo);
throw exc;
}
}
return str.str();
}