Index: mac/foundation_util.mm |
diff --git a/mac/foundation_util.mm b/mac/foundation_util.mm |
index 27d6e7c4653b50c95037652928361aad9b0a0ff3..bd5d51452dcf6a1d7ec63b9fd60a39a3a2931282 100644 |
--- a/mac/foundation_util.mm |
+++ b/mac/foundation_util.mm |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/mac/bundle_locations.h" |
#include "base/mac/mac_logging.h" |
+#include "base/numerics/safe_conversions.h" |
#include "base/strings/sys_string_conversions.h" |
#if !defined(OS_IOS) |
@@ -430,6 +431,19 @@ FilePath NSStringToFilePath(NSString* str) { |
return FilePath([str fileSystemRepresentation]); |
} |
+bool CFRangeToNSRange(CFRange range, NSRange* range_out) { |
+ if (base::IsValueInRangeForNumericType<decltype(range_out->location)>( |
+ range.location) && |
+ base::IsValueInRangeForNumericType<decltype(range_out->length)>( |
+ range.length) && |
+ base::IsValueInRangeForNumericType<decltype(range_out->location)>( |
+ range.location + range.length)) { |
+ *range_out = NSMakeRange(range.location, range.length); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
} // namespace mac |
} // namespace base |