henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Yves Gerey | 2e00abc | 2018-10-05 15:39:24 +0200 | [diff] [blame] | 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "rtc_base/string_utils.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 12 | |
Ali Tofigh | 7fa9057 | 2022-03-17 15:47:49 +0100 | [diff] [blame] | 13 | #include "absl/strings/string_view.h" |
| 14 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 15 | namespace rtc { |
| 16 | |
Niels Möller | d189252 | 2018-10-17 13:39:01 +0200 | [diff] [blame] | 17 | size_t strcpyn(char* buffer, |
| 18 | size_t buflen, |
| 19 | const char* source, |
| 20 | size_t srclen /* = SIZE_UNKNOWN */) { |
| 21 | if (buflen <= 0) |
| 22 | return 0; |
| 23 | |
| 24 | if (srclen == SIZE_UNKNOWN) { |
| 25 | srclen = strlen(source); |
| 26 | } |
| 27 | if (srclen >= buflen) { |
| 28 | srclen = buflen - 1; |
| 29 | } |
| 30 | memcpy(buffer, source, srclen); |
| 31 | buffer[srclen] = 0; |
| 32 | return srclen; |
| 33 | } |
| 34 | |
Jonas Olsson | 7439534 | 2018-04-03 12:22:07 +0200 | [diff] [blame] | 35 | std::string ToHex(const int i) { |
| 36 | char buffer[50]; |
| 37 | snprintf(buffer, sizeof(buffer), "%x", i); |
| 38 | |
| 39 | return std::string(buffer); |
| 40 | } |
| 41 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 42 | } // namespace rtc |