1 /*
2  * Copyright (C) 2015-2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <stdarg.h>
19 
20 //
21 // This file defines C and C++ replacements for scanf to parse a string in a
22 // locale-independent way. This is useful when parsing input data that comes
23 // not from user, but from some kind of a fixed protocol with predefined locale
24 // settings.
25 // Just use these functions as drop-in replacements of sscanf();
26 //
27 // Note1: if the input string contains any dot characters other than decimal
28 // separators, the results of parsing will be screwed: in Windows the
29 // implementation replaces all dots with the current decimal separator to parse
30 // using current locale.
31 // Note2: current implementation only supports parsing floating point numbers -
32 // no code for monetary values, dates, digit grouping etc.
33 // The limitation is because of MinGW's lack of per-thread locales support.
34 //
35 
36 #ifdef __cplusplus
37 #include <utility>
38 
39 extern "C" {
40 int SscanfWithCLocale(const char* string, const char* format, ...);
41 }
42 namespace cuttlefish {
43 
44 template <class... Args>
SscanfWithCLocale(const char * string,const char * format,Args...args)45 int SscanfWithCLocale(const char* string, const char* format, Args... args) {
46   return ::SscanfWithCLocale(string, format, std::forward<Args>(args)...);
47 }
48 
49 }  // namespace cuttlefish
50 
51 #endif  // __cplusplus
52