Subversion Repositories tpanel

Rev

Rev 44 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44 Rev 67
Line 368... Line 368...
368
	}
368
	}
369
 
369
 
370
	return out;
370
	return out;
371
}
371
}
372
 
372
 
-
 
373
string TNameFormat::strToHex(const unsigned char *str, size_t length, int width, bool format, int indent)
-
 
374
{
-
 
375
    DECL_TRACER("TNameFormat::strToHex(const unsigned char *str, int width, bool format, int indent)");
-
 
376
 
-
 
377
    int len = 0, pos = 0, old = 0;
-
 
378
    int w = (format) ? 1 : width;
-
 
379
    string out, left, right;
-
 
380
    string ind;
-
 
381
 
-
 
382
    if (indent > 0)
-
 
383
    {
-
 
384
        for (int j = 0; j < indent; j++)
-
 
385
            ind.append(" ");
-
 
386
    }
-
 
387
 
-
 
388
    for (size_t i = 0; i < length; i++)
-
 
389
    {
-
 
390
        if (len >= w)
-
 
391
        {
-
 
392
            left.append(" ");
-
 
393
            len = 0;
-
 
394
        }
-
 
395
 
-
 
396
        if (format && i > 0 && (pos % width) == 0)
-
 
397
        {
-
 
398
            out += ind + toHex(old, 4) + ": " + left + " | " + right + "\n";
-
 
399
            left.clear();
-
 
400
            right.clear();
-
 
401
            old = pos;
-
 
402
        }
-
 
403
 
-
 
404
        int c = *(str+i) & 0x000000ff;
-
 
405
        left.append(toHex(c, 2));
-
 
406
 
-
 
407
        if (format)
-
 
408
        {
-
 
409
            if (std::isprint(c))
-
 
410
                right.push_back(c);
-
 
411
            else
-
 
412
                right.push_back('.');
-
 
413
        }
-
 
414
 
-
 
415
        len++;
-
 
416
        pos++;
-
 
417
    }
-
 
418
 
-
 
419
    if (!format)
-
 
420
        return left;
-
 
421
    else if (pos > 0)
-
 
422
    {
-
 
423
        if ((pos % width) != 0)
-
 
424
        {
-
 
425
            for (int i = 0; i < (width - (pos % width)); i++)
-
 
426
                left.append("   ");
-
 
427
        }
-
 
428
 
-
 
429
        out += ind + toHex(old, 4)+": "+left + "  | " + right;
-
 
430
    }
-
 
431
 
-
 
432
    return out;
-
 
433
}
-
 
434
 
373
string TNameFormat::latin1ToUTF8(const string& str)
435
string TNameFormat::latin1ToUTF8(const string& str)
374
{
436
{
375
	DECL_TRACER("TNameFormat::latin1ToUTF8(const string& str)");
437
	DECL_TRACER("TNameFormat::latin1ToUTF8(const string& str)");
376
 
438
 
377
	string out;
439
	string out;