| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // Ask transformation function to approximate the destination size (returns up
per bound) | 549 // Ask transformation function to approximate the destination size (returns up
per bound) |
| 550 size_t maxlen = t(NULL, 0, source.data(), source.length()); | 550 size_t maxlen = t(NULL, 0, source.data(), source.length()); |
| 551 char * buffer = STACK_ARRAY(char, maxlen); | 551 char * buffer = STACK_ARRAY(char, maxlen); |
| 552 size_t len = t(buffer, maxlen, source.data(), source.length()); | 552 size_t len = t(buffer, maxlen, source.data(), source.length()); |
| 553 std::string result(buffer, len); | 553 std::string result(buffer, len); |
| 554 return result; | 554 return result; |
| 555 } | 555 } |
| 556 | 556 |
| 557 size_t tokenize(const std::string& source, char delimiter, | 557 size_t tokenize(const std::string& source, char delimiter, |
| 558 std::vector<std::string>* fields) { | 558 std::vector<std::string>* fields) { |
| 559 RTC_DCHECK(fields); | |
| 560 fields->clear(); | 559 fields->clear(); |
| 561 size_t last = 0; | 560 size_t last = 0; |
| 562 for (size_t i = 0; i < source.length(); ++i) { | 561 for (size_t i = 0; i < source.length(); ++i) { |
| 563 if (source[i] == delimiter) { | 562 if (source[i] == delimiter) { |
| 564 if (i != last) { | 563 if (i != last) { |
| 565 fields->push_back(source.substr(last, i - last)); | 564 fields->push_back(source.substr(last, i - last)); |
| 566 } | 565 } |
| 567 last = i + 1; | 566 last = i + 1; |
| 568 } | 567 } |
| 569 } | 568 } |
| 570 if (last != source.length()) { | 569 if (last != source.length()) { |
| 571 fields->push_back(source.substr(last, source.length() - last)); | 570 fields->push_back(source.substr(last, source.length() - last)); |
| 572 } | 571 } |
| 573 return fields->size(); | 572 return fields->size(); |
| 574 } | 573 } |
| 575 | 574 |
| 575 size_t tokenize_with_empty_tokens(const std::string& source, |
| 576 char delimiter, |
| 577 std::vector<std::string>* fields) { |
| 578 fields->clear(); |
| 579 size_t last = 0; |
| 580 for (size_t i = 0; i < source.length(); ++i) { |
| 581 if (source[i] == delimiter) { |
| 582 fields->push_back(source.substr(last, i - last)); |
| 583 last = i + 1; |
| 584 } |
| 585 } |
| 586 fields->push_back(source.substr(last, source.length() - last)); |
| 587 return fields->size(); |
| 588 } |
| 589 |
| 576 size_t tokenize_append(const std::string& source, char delimiter, | 590 size_t tokenize_append(const std::string& source, char delimiter, |
| 577 std::vector<std::string>* fields) { | 591 std::vector<std::string>* fields) { |
| 578 if (!fields) return 0; | 592 if (!fields) return 0; |
| 579 | 593 |
| 580 std::vector<std::string> new_fields; | 594 std::vector<std::string> new_fields; |
| 581 tokenize(source, delimiter, &new_fields); | 595 tokenize(source, delimiter, &new_fields); |
| 582 fields->insert(fields->end(), new_fields.begin(), new_fields.end()); | 596 fields->insert(fields->end(), new_fields.begin(), new_fields.end()); |
| 583 return fields->size(); | 597 return fields->size(); |
| 584 } | 598 } |
| 585 | 599 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 va_list args; | 688 va_list args; |
| 675 va_start(args, format); | 689 va_start(args, format); |
| 676 value.assign(buffer, vsprintfn(buffer, maxlen + 1, format, args)); | 690 value.assign(buffer, vsprintfn(buffer, maxlen + 1, format, args)); |
| 677 va_end(args); | 691 va_end(args); |
| 678 } | 692 } |
| 679 */ | 693 */ |
| 680 | 694 |
| 681 ///////////////////////////////////////////////////////////////////////////// | 695 ///////////////////////////////////////////////////////////////////////////// |
| 682 | 696 |
| 683 } // namespace rtc | 697 } // namespace rtc |
| OLD | NEW |