| 269 | } |
| 270 | |
| 271 | static PyObject* PyParseLabelText( PyObject* self, PyObject* args ) |
| 272 | { |
| 273 | #if PY_MAJOR_VERSION == 2 |
| 274 | wchar_t* paramString; |
| 275 | if( !PyArg_ParseTuple( args, "u", ¶mString ) ) |
| 276 | { |
| 277 | return nullptr; |
| 278 | } |
| 279 | |
| 280 | size_t stringLength = wcslen( paramString ); |
| 281 | #else |
| 282 | PyObject* paramObject; |
| 283 | if( !PyArg_ParseTuple( args, "U", ¶mObject ) ) |
| 284 | { |
| 285 | return nullptr; |
| 286 | } |
| 287 | Py_ssize_t stringLength; |
| 288 | wchar_t* paramString = PyUnicode_AsWideCharString( paramObject, &stringLength ); |
| 289 | if( !paramString ) |
| 290 | { |
| 291 | return nullptr; |
| 292 | } |
| 293 | #endif |
| 294 | wchar_t* inString = CCP_NEW( "ParseLabelText" ) wchar_t[stringLength + 1]; |
| 295 | wcscpy_s( inString, stringLength + 1, paramString ); |
| 296 | |
| 297 | PyObject* listOfLines = PyList_New( 0 ); |
| 298 | |
| 299 | PyObject* currentLine = PyList_New( 0 ); |
| 300 | PyObject* currentTab = PyList_New( 0 ); |
| 301 | PyList_Append( listOfLines, currentLine ); |
| 302 | PyList_Append( currentLine, currentTab ); |
| 303 | |
| 304 | // The list now owns the references |
| 305 | Py_DECREF( currentLine ); |
| 306 | Py_DECREF( currentTab ); |
| 307 | |
| 308 | wchar_t* curPos = inString; |
| 309 | wchar_t* marker = curPos; |
| 310 | |
| 311 | std::wstring stringBeingBuilt; // Can't just copy straight over 'cause we sometimes do text replacements, like & |
| 312 | |
| 313 | States state = STATE_ROOT; |
| 314 | |
| 315 | while( state != STATE_TERMINATE ) |
| 316 | { |
| 317 | switch( state ) |
| 318 | { |
| 319 | case STATE_ROOT: // Very simple state for starting out, we're either at a tag or we aren't. |
| 320 | if( *curPos == L'<' ) |
| 321 | { |
| 322 | marker = curPos; |
| 323 | curPos++; |
| 324 | state = STATE_TAG; |
| 325 | } |
| 326 | else if( *curPos == L'\0' ) |
| 327 | { |
| 328 | state = STATE_TERMINATE; |
nothing calls this directly
no test coverage detected