blob: 077bdcc48b867e413e0de937e487464854c4db4c [file] [log] [blame]
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00001//
2// Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Langdcefb752013-12-04 15:54:27 -05007#include "compiler/translator/util.h"
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00008
Zhenyao Mo521c8362013-08-29 15:17:04 -07009#include <limits>
10
Zhenyao Mof382bff2013-09-09 13:20:27 -070011#include "compiler/preprocessor/numeric_lex.h"
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000012
Zhenyao Mo521c8362013-08-29 15:17:04 -070013bool atof_clamp(const char *str, float *value)
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000014{
Zhenyao Mof382bff2013-09-09 13:20:27 -070015 bool success = pp::numeric_lex_float(str, value);
Zhenyao Mo521c8362013-08-29 15:17:04 -070016 if (!success)
17 *value = std::numeric_limits<float>::max();
18 return success;
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000019}
Zhenyao Mo521c8362013-08-29 15:17:04 -070020
21bool atoi_clamp(const char *str, int *value)
22{
Zhenyao Mof382bff2013-09-09 13:20:27 -070023 bool success = pp::numeric_lex_int(str, value);
24 if (!success)
Zhenyao Mo521c8362013-08-29 15:17:04 -070025 *value = std::numeric_limits<int>::max();
Zhenyao Mof382bff2013-09-09 13:20:27 -070026 return success;
Zhenyao Mo521c8362013-08-29 15:17:04 -070027}
28