Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 16 | */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 17 | |
| 18 | #include "svox_ssml_parser.h" |
| 19 | #include <utils/Log.h> |
| 20 | #include <cutils/jstring.h> |
| 21 | #include <string.h> |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 22 | #include <utils/String16.h> |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 23 | |
| 24 | #define SSML_PITCH_XLOW "50" |
| 25 | #define SSML_PITCH_LOW "75" |
| 26 | #define SSML_PITCH_MEDIUM "100" |
| 27 | #define SSML_PITCH_HIGH "150" |
| 28 | #define SSML_PITCH_XHIGH "200" |
| 29 | #define SSML_RATE_XSLOW "30" |
| 30 | #define SSML_RATE_SLOW "60" |
| 31 | #define SSML_RATE_MEDIUM "100" |
| 32 | #define SSML_RATE_FAST "250" |
| 33 | #define SSML_RATE_XFAST "500" |
| 34 | #define SSML_VOLUME_SILENT "0" |
Charles Chen | 474a319 | 2009-07-17 18:02:16 -0700 | [diff] [blame] | 35 | #define SSML_VOLUME_XLOW "25" |
| 36 | #define SSML_VOLUME_LOW "70" |
Jean-Michel Trivi | 0e684c3 | 2009-07-21 18:17:27 -0700 | [diff] [blame] | 37 | #define SSML_VOLUME_MEDIUM "120" |
| 38 | #define SSML_VOLUME_LOUD "300" |
| 39 | #define SSML_VOLUME_XLOUD "450" |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 40 | #define SSML_BREAK_NONE "0ms" |
| 41 | #define SSML_BREAK_XWEAK "100ms" |
| 42 | #define SSML_BREAK_WEAK "300ms" |
| 43 | #define SSML_BREAK_MEDIUM "600ms" |
| 44 | #define SSML_BREAK_STRONG "1s" |
| 45 | #define SSML_BREAK_XSTRONG "3s" |
| 46 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 47 | extern int cnvIpaToXsampa(const char16_t* ipaString, size_t ipaStringSize, char** outXsampaString); |
| 48 | extern char * createPhonemeString( const char * xsampa, int length ); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 49 | |
| 50 | SvoxSsmlParser::SvoxSsmlParser() : m_isInBreak(0), m_appendix(NULL), m_docLanguage(NULL) |
| 51 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 52 | mParser = XML_ParserCreate("UTF-8"); |
| 53 | if (mParser) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 54 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 55 | XML_SetElementHandler(mParser, starttagHandler, endtagHandler); |
| 56 | XML_SetCharacterDataHandler(mParser, textHandler); |
| 57 | XML_SetUserData(mParser, (void*)this); |
| 58 | m_datasize = 512; |
| 59 | m_data = new char[m_datasize]; |
| 60 | m_data[0] = '\0'; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | SvoxSsmlParser::~SvoxSsmlParser() |
| 65 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 66 | if (mParser) |
| 67 | XML_ParserFree(mParser); |
| 68 | if (m_data) |
| 69 | delete [] m_data; |
| 70 | if (m_appendix) |
| 71 | delete [] m_appendix; |
| 72 | if (m_docLanguage) |
| 73 | delete [] m_docLanguage; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | int SvoxSsmlParser::initSuccessful() |
| 77 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 78 | return (mParser && m_data); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int SvoxSsmlParser::parseDocument(const char* ssmldoc, int isFinal) |
| 82 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 83 | int doclen = (int)strlen(ssmldoc) + 1; |
| 84 | int status = XML_Parse(mParser, ssmldoc, doclen, isFinal); |
| 85 | if (status == XML_STATUS_ERROR) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 86 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 87 | /* Note: for some reason Expat almost always complains about invalid tokens, even when document is well formed */ |
Steve Block | 659851c | 2012-01-04 20:01:45 +0000 | [diff] [blame] | 88 | ALOGI("Parser error at line %d: %s\n", (int)XML_GetCurrentLineNumber(mParser), XML_ErrorString(XML_GetErrorCode(mParser))); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 89 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 90 | return status; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | char* SvoxSsmlParser::getParsedDocument() |
| 94 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 95 | return m_data; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | char* SvoxSsmlParser::getParsedDocumentLanguage() |
| 99 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 100 | return m_docLanguage; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void SvoxSsmlParser::starttagHandler(void* data, const XML_Char* element, const XML_Char** attributes) |
| 104 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 105 | ((SvoxSsmlParser*)data)->startElement(element, attributes); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void SvoxSsmlParser::startElement(const XML_Char* element, const XML_Char** attributes) |
| 109 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 110 | if (strcmp(element, "speak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 111 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 112 | if (strlen(m_data) > 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 113 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 114 | /* we have old data, get rid of it and reallocate memory */ |
| 115 | delete m_data; |
| 116 | m_data = NULL; |
| 117 | m_datasize = 512; |
| 118 | m_data = new char[m_datasize]; |
| 119 | if (!m_data) |
| 120 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 121 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 122 | return; |
| 123 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 124 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 125 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 126 | /* the only attribute supported in the speak tag is xml:lang, all others are ignored */ |
| 127 | for (int i = 0; attributes[i]; i += 2) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 128 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 129 | if (strcmp(attributes[i], "xml:lang") == 0) |
| 130 | { |
| 131 | if (!m_docLanguage) |
| 132 | { |
| 133 | m_docLanguage = new char[strlen(attributes[i+1])+1]; |
| 134 | } |
| 135 | strcpy(m_docLanguage, attributes[i+1]); |
| 136 | break; |
| 137 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 140 | else if (strcmp(element, "p") == 0) /* currently no attributes are supported for <p> */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 141 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 142 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 143 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 144 | if (!growDataSize(100)) |
| 145 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 146 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 147 | return; |
| 148 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 149 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 150 | strcat(m_data, "<p>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 151 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 152 | else if (strcmp(element, "s") == 0) /* currently no attributes are supported for <s> */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 153 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 154 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 155 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 156 | if (!growDataSize(100)) |
| 157 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 158 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 159 | return; |
| 160 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 161 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 162 | strcat(m_data, "<s>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 163 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 164 | else if (strcmp(element, "phoneme") == 0) /* only ipa and xsampa alphabets are supported */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 165 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 166 | int alpha = 1; /* set to 1 if alphabet is ipa */ |
| 167 | int tagComplete = 0; /* set to 1 if phoneme tag has already been added */ |
| 168 | char16_t* ph = NULL; |
| 169 | char* xsampastr = NULL; |
| 170 | size_t phsize = 0; |
| 171 | size_t xsampasize = 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 172 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 173 | for (int i = 0; attributes[i]; i += 2) |
| 174 | { |
| 175 | if (strcmp(attributes[i], "alphabet") == 0) |
| 176 | { |
| 177 | if (strcmp(attributes[i+1], "xsampa") == 0) |
| 178 | { |
| 179 | alpha = 0; |
| 180 | } |
| 181 | } |
| 182 | if (strcmp(attributes[i], "ph") == 0) |
| 183 | { |
| 184 | ph = new char16_t[strlen8to16(attributes[i+1]) + 1]; |
| 185 | ph = strdup8to16(attributes[i+1], &phsize); |
| 186 | } |
| 187 | } |
| 188 | if (!ph) |
| 189 | { |
| 190 | /* error, no phonetic string */ |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 191 | ALOGE("Error: bad SSML syntax, ph attribute not supplied."); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 192 | return; |
| 193 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 194 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 195 | if (alpha) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 196 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 197 | /* need to convert phoneme string to xsampa */ |
| 198 | xsampasize = cnvIpaToXsampa(ph, phsize, &xsampastr); |
| 199 | delete [] ph; |
| 200 | if (!xsampastr) |
| 201 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 202 | ALOGE("Error: failed to allocate memory for IPA string conversion"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | } |
| 206 | else |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 207 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 208 | xsampastr = strndup16to8(ph, phsize); |
| 209 | xsampasize = strlen(xsampastr); |
| 210 | delete [] ph; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 211 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 212 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 213 | /* split XSAMPA string into multiple phonemes if needed */ |
| 214 | if (strstr(xsampastr, " ") || strstr(xsampastr, "#")) /* check again to see if we have multiple words */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 215 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 216 | char* phonstr = createPhonemeString(xsampastr, strlen(xsampastr) + 1); |
| 217 | free(xsampastr); |
| 218 | xsampastr = NULL; |
| 219 | xsampastr = (char*)malloc(strlen(phonstr) + 1); |
| 220 | strcpy(xsampastr, phonstr); |
| 221 | free(phonstr); |
| 222 | phonstr = NULL; |
| 223 | tagComplete = 1; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 224 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 225 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 226 | if (tagComplete) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 227 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 228 | if (strlen(m_data) + strlen(xsampastr) + 1 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 229 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 230 | if (!growDataSize(100)) |
| 231 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 232 | ALOGE("Error: failed to allocate memory for string!"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 233 | free(xsampastr); |
| 234 | return; |
| 235 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 238 | else |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 239 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 240 | if (strlen(m_data) + strlen(xsampastr) + 17 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 241 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 242 | if (!growDataSize(100)) |
| 243 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 244 | ALOGE("Error: failed to allocate memory for string!"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 245 | free(xsampastr); |
| 246 | return; |
| 247 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 248 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 249 | strcat(m_data, "<phoneme ph='"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 250 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 251 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 252 | strcat(m_data, xsampastr); |
| 253 | free(xsampastr); |
| 254 | |
| 255 | if (!tagComplete) |
| 256 | { |
| 257 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
| 258 | { |
| 259 | if (!growDataSize(100)) |
| 260 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 261 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | } |
| 265 | strcat(m_data, "'/>"); |
| 266 | } |
| 267 | |
| 268 | m_isInBreak = 1; /* set flag to indicate any text between open and close tag is to be discarded */ |
| 269 | } |
| 270 | else if (strcmp(element, "break") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 271 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 272 | if (strlen(m_data) + 17 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 273 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 274 | if (!growDataSize(100)) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 275 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 276 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 277 | return; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 280 | strcat(m_data, "<break time='"); |
| 281 | char* time = NULL; |
| 282 | |
| 283 | for (int i = 0; attributes[i]; i += 2) |
| 284 | { |
| 285 | if (strcmp(attributes[i], "time") == 0) |
| 286 | { |
| 287 | time = new char[strlen(attributes[i+1]) + 1]; |
| 288 | if (!time) |
| 289 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 290 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | strcpy(time, attributes[i+1]); |
| 294 | } |
| 295 | else if (strcmp(attributes[i], "strength") == 0 && !time) |
| 296 | { |
| 297 | time = convertBreakStrengthToTime(attributes[i+1]); |
| 298 | } |
| 299 | } |
| 300 | if (!time) |
| 301 | { |
| 302 | time = new char[6]; |
| 303 | if (!time) |
| 304 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 305 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 306 | return; |
| 307 | } |
| 308 | strcpy(time, SSML_BREAK_WEAK); /* if no time or strength attributes are specified, default to weak break */ |
| 309 | } |
| 310 | if (strlen(m_data) + strlen(time) + 4 > (size_t)m_datasize) |
| 311 | { |
| 312 | if (!growDataSize(100)) |
| 313 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 314 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | } |
| 318 | strcat(m_data, time); |
| 319 | strcat(m_data, "'/>"); |
| 320 | m_isInBreak = 1; /* set flag to indicate any text between open and close tag is to be discarded */ |
| 321 | } |
| 322 | else if (strcmp(element, "prosody") == 0) /* only pitch, rate and volume attributes are supported */ |
| 323 | { |
| 324 | for (int i = 0; attributes[i]; i += 2) |
| 325 | { |
| 326 | if (strcmp(attributes[i], "pitch") == 0) |
| 327 | { |
| 328 | char* svoxpitch = convertToSvoxPitch(attributes[i+1]); |
| 329 | if (!svoxpitch) |
| 330 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 331 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 332 | return; |
| 333 | } |
| 334 | if (!svoxpitch) |
| 335 | { |
| 336 | svoxpitch = new char[4]; |
| 337 | if (!svoxpitch) |
| 338 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 339 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 340 | return; |
| 341 | } |
| 342 | strcpy(svoxpitch, "100"); |
| 343 | } |
| 344 | char* pitch = new char[17 + strlen(svoxpitch)]; |
| 345 | if (!pitch) |
| 346 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 347 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 348 | return; |
| 349 | } |
| 350 | sprintf(pitch, "<pitch level='%s'>", svoxpitch); |
| 351 | if (strlen(m_data) + strlen(pitch) + 1 > (size_t)m_datasize) |
| 352 | { |
| 353 | if (!growDataSize(100)) |
| 354 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 355 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 356 | return; |
| 357 | } |
| 358 | } |
| 359 | strcat(m_data, pitch); |
| 360 | if (!m_appendix) |
| 361 | { |
| 362 | m_appendix = new char[30]; |
| 363 | m_appendix[0] = '\0'; |
| 364 | } |
| 365 | strcat(m_appendix, "</pitch>"); |
| 366 | delete [] svoxpitch; |
| 367 | delete [] pitch; |
| 368 | } |
| 369 | else if (strcmp(attributes[i], "rate") == 0) |
| 370 | { |
| 371 | char* svoxrate = convertToSvoxRate(attributes[i+1]); |
| 372 | if (!svoxrate) |
| 373 | { |
| 374 | svoxrate = new char[4]; |
| 375 | if (!svoxrate) |
| 376 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 377 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 378 | return; |
| 379 | } |
| 380 | strcpy(svoxrate, "100"); |
| 381 | } |
| 382 | char* rate = new char[17 + strlen(svoxrate)]; |
| 383 | if (!rate) |
| 384 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 385 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 386 | return; |
| 387 | } |
| 388 | sprintf(rate, "<speed level='%s'>", svoxrate); |
| 389 | if (strlen(m_data) + strlen(rate) + 1 > (size_t)m_datasize) |
| 390 | { |
| 391 | if (!growDataSize(100)) |
| 392 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 393 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 394 | return; |
| 395 | } |
| 396 | } |
| 397 | strcat(m_data, rate); |
| 398 | if (!m_appendix) |
| 399 | { |
| 400 | m_appendix = new char[30]; |
| 401 | if (!m_appendix) |
| 402 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 403 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 404 | return; |
| 405 | } |
| 406 | m_appendix[0] = '\0'; |
| 407 | } |
| 408 | strcat(m_appendix, "</speed>"); |
| 409 | delete [] svoxrate; |
| 410 | delete [] rate; |
| 411 | } |
| 412 | else if (strcmp(attributes[i], "volume") == 0) |
| 413 | { |
| 414 | char* svoxvol = convertToSvoxVolume(attributes[i+1]); |
| 415 | if (!svoxvol) |
| 416 | { |
| 417 | svoxvol = new char[4]; |
| 418 | if (!svoxvol) |
| 419 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 420 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | strcpy(svoxvol, "100"); |
| 424 | } |
| 425 | char* volume = new char[18 + strlen(svoxvol)]; |
| 426 | if (!volume) |
| 427 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 428 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 429 | return; |
| 430 | } |
| 431 | sprintf(volume, "<volume level='%s'>", svoxvol); |
| 432 | if (strlen(m_data) + strlen(volume) + 1 > (size_t)m_datasize) |
| 433 | { |
| 434 | if (!growDataSize(100)) |
| 435 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 436 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | } |
| 440 | strcat(m_data, volume); |
| 441 | if (!m_appendix) |
| 442 | { |
| 443 | m_appendix = new char[30]; |
| 444 | m_appendix[0] = '\0'; |
| 445 | } |
| 446 | strcat(m_appendix, "</volume>"); |
| 447 | delete [] svoxvol; |
| 448 | delete [] volume; |
| 449 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 452 | else if (strcmp(element, "audio") == 0) /* only 16kHz 16bit wav files are supported as src */ |
| 453 | { |
| 454 | if (strlen(m_data) + 17 > (size_t)m_datasize) |
| 455 | { |
| 456 | if (!growDataSize(100)) |
| 457 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 458 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | } |
| 462 | strcat(m_data, "<usesig file='"); |
| 463 | |
| 464 | for (int i = 0; attributes[i]; i += 2) |
| 465 | { |
| 466 | if (strcmp(attributes[i], "src") == 0) |
| 467 | { |
| 468 | if (strlen(m_data) + strlen(attributes[i+1]) + 1 > (size_t)m_datasize) |
| 469 | { |
| 470 | if (!growDataSize(100)) |
| 471 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 472 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | } |
| 476 | strcat(m_data, attributes[i+1]); |
| 477 | } |
| 478 | } |
| 479 | strcat(m_data, "'>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | void SvoxSsmlParser::endtagHandler(void* data, const XML_Char* element) |
| 484 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 485 | ((SvoxSsmlParser*)data)->endElement(element); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | void SvoxSsmlParser::endElement(const XML_Char* element) |
| 489 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 490 | if (strcmp(element, "speak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 491 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 492 | /* do nothing */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 493 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 494 | else if (strcmp(element, "p") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 495 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 496 | if (strlen(m_data) + 5 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 497 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 498 | if (!growDataSize(100)) |
| 499 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 500 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 501 | return; |
| 502 | } |
| 503 | } |
| 504 | strcat(m_data, "</p>"); |
| 505 | } |
| 506 | else if (strcmp(element, "s") == 0) |
| 507 | { |
| 508 | if (strlen(m_data) + 5 > (size_t)m_datasize) |
| 509 | { |
| 510 | if (!growDataSize(100)) |
| 511 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 512 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
| 515 | } |
| 516 | strcat(m_data, "</s>"); |
| 517 | } |
| 518 | else if (strcmp(element, "phoneme") == 0) |
| 519 | { |
| 520 | m_isInBreak = 0; /* indicate we are no longer in phoneme tag */ |
| 521 | } |
| 522 | else if (strcmp(element, "break") == 0) |
| 523 | { |
| 524 | m_isInBreak = 0; /* indicate we are no longer in break tag */ |
| 525 | } |
| 526 | else if (strcmp(element, "prosody") == 0) |
| 527 | { |
| 528 | if (m_appendix) |
| 529 | { |
| 530 | if (strlen(m_data) + strlen(m_appendix) + 1 > (size_t)m_datasize) |
| 531 | { |
| 532 | if (!growDataSize(100)) |
| 533 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 534 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | } |
| 538 | strcat(m_data, m_appendix); |
| 539 | delete [] m_appendix; |
| 540 | m_appendix = NULL; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 543 | else if (strcmp(element, "audio") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 544 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 545 | if (strlen(m_data) + 10 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 546 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 547 | if (!growDataSize(100)) |
| 548 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 549 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 550 | return; |
| 551 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 552 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 553 | strcat(m_data, "</usesig>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | void SvoxSsmlParser::textHandler(void* data, const XML_Char* text, int length) |
| 558 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 559 | ((SvoxSsmlParser*)data)->textElement(text, length); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | void SvoxSsmlParser::textElement(const XML_Char* text, int length) |
| 563 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 564 | if (m_isInBreak) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 565 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 566 | return; /* handles the case when someone has added text inside the break or phoneme tag - this text is thrown away */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 569 | char* content = new char[length + 1]; |
| 570 | if (!content) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 571 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 572 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 573 | return; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 574 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 575 | strncpy(content, text, length); |
| 576 | content[length] = '\0'; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 577 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 578 | if (strlen(m_data) + strlen(content) + 1 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 579 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 580 | if (!growDataSize(100)) |
| 581 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 582 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 583 | return; |
| 584 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 585 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 586 | strcat(m_data, content); |
| 587 | delete [] content; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 591 | convertToSvoxPitch |
| 592 | Converts SSML pitch labels to SVOX pitch levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 593 | */ |
| 594 | char* SvoxSsmlParser::convertToSvoxPitch(const char* value) |
| 595 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 596 | char* converted = NULL; |
| 597 | if (strcmp(value, "x-low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 598 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 599 | converted = new char[4]; |
| 600 | if (!converted) |
| 601 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 602 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 603 | return NULL; |
| 604 | } |
| 605 | strcpy(converted, SSML_PITCH_XLOW); |
| 606 | } |
| 607 | else if (strcmp(value, "low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 608 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 609 | converted = new char[4]; |
| 610 | if (!converted) |
| 611 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 612 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 613 | return NULL; |
| 614 | } |
| 615 | strcpy(converted, SSML_PITCH_LOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 616 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 617 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 618 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 619 | converted = new char[4]; |
| 620 | if (!converted) |
| 621 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 622 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 623 | return NULL; |
| 624 | } |
| 625 | strcpy(converted, SSML_PITCH_MEDIUM); |
| 626 | } |
| 627 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 628 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 629 | converted = new char[4]; |
| 630 | if (!converted) |
| 631 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 632 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 633 | return NULL; |
| 634 | } |
| 635 | strcpy(converted, SSML_PITCH_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 636 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 637 | else if (strcmp(value, "high") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 638 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 639 | converted = new char[4]; |
| 640 | if (!converted) |
| 641 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 642 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 643 | return NULL; |
| 644 | } |
| 645 | strcpy(converted, SSML_PITCH_HIGH); |
| 646 | } |
| 647 | else if (strcmp(value, "x-high") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 648 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 649 | converted = new char[4]; |
| 650 | if (!converted) |
| 651 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 652 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 653 | return NULL; |
| 654 | } |
| 655 | strcpy(converted, SSML_PITCH_XHIGH); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 656 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 657 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 661 | convertToSvoxRate |
| 662 | Converts SSML rate labels to SVOX speed levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 663 | */ |
| 664 | char* SvoxSsmlParser::convertToSvoxRate(const char* value) |
| 665 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 666 | char* converted = NULL; |
| 667 | if (strcmp(value, "x-slow") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 668 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 669 | converted = new char[4]; |
| 670 | if (!converted) |
| 671 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 672 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 673 | return NULL; |
| 674 | } |
| 675 | strcpy(converted, SSML_RATE_XSLOW); |
| 676 | } |
| 677 | else if (strcmp(value, "slow") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 678 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 679 | converted = new char[4]; |
| 680 | if (!converted) |
| 681 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 682 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 683 | return NULL; |
| 684 | } |
| 685 | strcpy(converted, SSML_RATE_SLOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 686 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 687 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 688 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 689 | converted = new char[4]; |
| 690 | if (!converted) |
| 691 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 692 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 693 | return NULL; |
| 694 | } |
| 695 | strcpy(converted, SSML_RATE_MEDIUM); |
| 696 | } |
| 697 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 698 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 699 | converted = new char[4]; |
| 700 | if (!converted) |
| 701 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 702 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 703 | return NULL; |
| 704 | } |
| 705 | strcpy(converted, SSML_RATE_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 706 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 707 | else if (strcmp(value, "fast") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 708 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 709 | converted = new char[4]; |
| 710 | if (!converted) |
| 711 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 712 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 713 | return NULL; |
| 714 | } |
| 715 | strcpy(converted, SSML_RATE_FAST); |
| 716 | } |
| 717 | else if (strcmp(value, "x-fast") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 718 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 719 | converted = new char[4]; |
| 720 | if (!converted) |
| 721 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 722 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 723 | return NULL; |
| 724 | } |
| 725 | strcpy(converted, SSML_RATE_XFAST); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 726 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 727 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 731 | convertToSvoxVolume |
| 732 | Converts SSML volume labels to SVOX volume levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 733 | */ |
| 734 | char* SvoxSsmlParser::convertToSvoxVolume(const char* value) |
| 735 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 736 | char* converted = NULL; |
| 737 | if (strcmp(value, "silent") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 738 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 739 | converted = new char[4]; |
| 740 | if (!converted) |
| 741 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 742 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 743 | return NULL; |
| 744 | } |
| 745 | strcpy(converted, SSML_VOLUME_SILENT); |
| 746 | } |
| 747 | else if (strcmp(value, "x-low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 748 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 749 | converted = new char[4]; |
| 750 | if (!converted) |
| 751 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 752 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 753 | return NULL; |
| 754 | } |
| 755 | strcpy(converted, SSML_VOLUME_XLOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 756 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 757 | else if (strcmp(value, "low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 758 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 759 | converted = new char[4]; |
| 760 | if (!converted) |
| 761 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 762 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 763 | return NULL; |
| 764 | } |
| 765 | strcpy(converted, SSML_VOLUME_LOW); |
| 766 | } |
| 767 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 768 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 769 | converted = new char[4]; |
| 770 | if (!converted) |
| 771 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 772 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 773 | return NULL; |
| 774 | } |
| 775 | strcpy(converted, SSML_VOLUME_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 776 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 777 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 778 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 779 | converted = new char[4]; |
| 780 | if (!converted) |
| 781 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 782 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 783 | return NULL; |
| 784 | } |
| 785 | strcpy(converted, SSML_VOLUME_MEDIUM); |
| 786 | } |
| 787 | else if (strcmp(value, "loud") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 788 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 789 | converted = new char[4]; |
| 790 | if (!converted) |
| 791 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 792 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 793 | return NULL; |
| 794 | } |
| 795 | strcpy(converted, SSML_VOLUME_LOUD); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 796 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 797 | else if (strcmp(value, "x-loud") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 798 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 799 | converted = new char[4]; |
| 800 | if (!converted) |
| 801 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 802 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 803 | return NULL; |
| 804 | } |
| 805 | strcpy(converted, SSML_VOLUME_XLOUD); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 806 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 807 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 811 | convertBreakStrengthToTime |
| 812 | Converts SSML break strength labels to SVOX break time |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 813 | */ |
| 814 | char* SvoxSsmlParser::convertBreakStrengthToTime(const char* value) |
| 815 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 816 | char* converted = NULL; |
| 817 | if (strcmp(value, "none") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 818 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 819 | converted = new char[6]; |
| 820 | if (!converted) |
| 821 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 822 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 823 | return NULL; |
| 824 | } |
| 825 | strcpy(converted, SSML_BREAK_NONE); |
| 826 | } |
| 827 | else if (strcmp(value, "x-weak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 828 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 829 | converted = new char[6]; |
| 830 | if (!converted) |
| 831 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 832 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 833 | return NULL; |
| 834 | } |
| 835 | strcpy(converted, SSML_BREAK_XWEAK); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 836 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 837 | else if (strcmp(value, "weak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 838 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 839 | converted = new char[6]; |
| 840 | if (!converted) |
| 841 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 842 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 843 | return NULL; |
| 844 | } |
| 845 | strcpy(converted, SSML_BREAK_WEAK); |
| 846 | } |
| 847 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 848 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 849 | converted = new char[6]; |
| 850 | if (!converted) |
| 851 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 852 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 853 | return NULL; |
| 854 | } |
| 855 | strcpy(converted, SSML_BREAK_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 856 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 857 | else if (strcmp(value, "strong") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 858 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 859 | converted = new char[6]; |
| 860 | if (!converted) |
| 861 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 862 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 863 | return NULL; |
| 864 | } |
| 865 | strcpy(converted, SSML_BREAK_STRONG); |
| 866 | } |
| 867 | else if (strcmp(value, "x-strong") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 868 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 869 | converted = new char[6]; |
| 870 | if (!converted) |
| 871 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 872 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 873 | return NULL; |
| 874 | } |
| 875 | strcpy(converted, SSML_BREAK_XSTRONG); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 876 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 877 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 881 | growDataSize |
| 882 | Increases the size of the internal text storage member |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 883 | */ |
| 884 | int SvoxSsmlParser::growDataSize(int sizeToGrow) |
| 885 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 886 | char* tmp = new char[m_datasize]; |
| 887 | if (!tmp) |
| 888 | return 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 889 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 890 | strcpy(tmp, m_data); |
| 891 | delete [] m_data; |
| 892 | m_data = NULL; |
| 893 | m_data = new char[m_datasize + sizeToGrow]; |
| 894 | if (!m_data) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 895 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 896 | m_data = tmp; |
| 897 | return 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 898 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 899 | m_datasize += sizeToGrow; |
| 900 | strcpy(m_data, tmp); |
| 901 | delete [] tmp; |
| 902 | tmp = NULL; |
| 903 | return 1; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 904 | } |