OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #include "debugger/rsp/rsp_blob_utils.h" | |
5 #include <stdarg.h> | |
6 #include <stdio.h> | |
7 #include "debugger/rsp/rsp_packets.h" | |
8 | |
9 namespace rsp { | |
10 void RemoveSpacesFromBothEnds(debug::Blob* blob) { | |
11 while (blob->size() != 0) { | |
12 char c = blob->Front(); | |
13 if (isspace(c)) | |
14 blob->PopFront(); | |
15 else | |
16 break; | |
17 } | |
18 while (blob->size() != 0) { | |
19 char c = blob->Back(); | |
20 if (isspace(c)) | |
21 blob->PopBack(); | |
22 else | |
23 break; | |
24 } | |
25 } | |
26 | |
27 void RemoveSpacesFromBothEnds(std::deque<debug::Blob>* blobs) { | |
28 std::deque<debug::Blob>::iterator it = blobs->begin(); | |
29 while (it != blobs->end()) { | |
30 debug::Blob& blob = *it++; | |
31 RemoveSpacesFromBothEnds(&blob); | |
32 } | |
33 } | |
34 | |
35 debug::Blob& Format(debug::Blob* blob, const char* fmt, ...) { | |
36 va_list marker; | |
37 va_start(marker, fmt); | |
38 char buff[rsp::kMaxRspPacketSize * 2]; | |
39 #ifdef _WIN32 | |
40 signed int res = _vsnprintf_s(buff, sizeof(buff) - 1, fmt, marker); | |
41 #else | |
42 signed int res = vsnprintf(buff, sizeof(buff) - 1, fmt, marker); | |
43 #endif | |
44 if (-1 != res) { | |
45 buff[sizeof(buff) - 1] = 0; | |
46 buff[res] = 0; | |
47 blob->FromString(buff); | |
48 } | |
49 return *blob; | |
50 } | |
51 } // namespace rsp | |
52 | |
OLD | NEW |