MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / ExtractString

Method ExtractString

cpp/src/command_classes/NodeNaming.cpp:398–468  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Extract a string from the report data -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

396// Extract a string from the report data
397//-----------------------------------------------------------------------------
398string OpenZWave::ExtractString
399(
400 uint8 const* _data,
401 uint32 const _length
402)
403{
404 uint8 i;
405 char str[32];
406 uint32 pos = 0;
407
408 str[0] = 0;
409 StringEncoding encoding = (StringEncoding)( _data[1] & 0x07 );
410
411 if( _length >= 3 )
412 {
413 // Get the length of the string (maximum allowed is 16 bytes)
414 uint8 numBytes = _length - 3;
415 if( numBytes > 16 )
416 {
417 numBytes = 16;
418 }
419
420 switch( encoding )
421 {
422 case StringEncoding_ASCII:
423 {
424 // Copy data as-is
425 for( i=0; i<numBytes; ++i )
426 {
427 str[pos++] = _data[i+2];
428 }
429 break;
430 }
431 case StringEncoding_ExtendedASCII:
432 {
433 // Convert Extended ASCII characters to UTF-8
434 for( i=0; i<numBytes; ++i )
435 {
436 uint8 ch = _data[i+2];
437 if( ch >= 0x80 )
438 {
439 uint16 utf16 = c_extendedAsciiToUnicode[ch-0x80];
440 pos = ConvertUFT16ToUTF8( utf16, str, pos );
441 }
442 else
443 {
444 str[pos++] = (char)ch;
445 }
446 }
447 break;
448 }
449 case StringEncoding_UTF16:
450 {
451 // Convert UTF-16 characters to UTF-8
452 for( i=0; i<numBytes; i+=2 )
453 {
454 uint16 utf16 = (((uint16)_data[i+2])<<8) | (uint16)_data[i+3];
455 pos = ConvertUFT16ToUTF8( utf16, str, pos );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected