/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include double osg::asciiToDouble(const char* str) { const char* ptr = str; // check if could be a hex number. if (strncmp(ptr,"0x",2)==0) { double value = 0.0; // skip over leading 0x, and then go through rest of string // checking to make sure all values are 0...9 or a..f. ptr+=2; while ( *ptr!=0 && ((*ptr>='0' && *ptr<='9') || (*ptr>='a' && *ptr<='f') || (*ptr>='A' && *ptr<='F')) ) { if (*ptr>='0' && *ptr<='9') value = value*16.0 + double(*ptr-'0'); else if (*ptr>='a' && *ptr<='f') value = value*16.0 + double(*ptr-'a'+10); else if (*ptr>='A' && *ptr<='F') value = value*16.0 + double(*ptr-'A'+10); ++ptr; } // OSG_NOTICE<<"Read "<