1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 Read a non-delimited hex label
27 \*---------------------------------------------------------------------------*/
29 #include "readHexLabel.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 Foam::label Foam::readHexLabel(ISstream& is)
36 // Takes into account that 'a' (or 'A') is 10
37 static const label alphaOffset = toupper('A') - 10;
38 // Takes into account that '0' is 0
39 static const label zeroOffset = int('0');
43 // Get next non-whitespace character
44 while (is.get(c) && isspace(c))
47 register label result = 0;
50 if (isspace(c) || c == 0) break;
54 FatalIOErrorIn("readHexLabel(ISstream&)", is)
55 << "Illegal hex digit: '" << c << "'"
56 << exit(FatalIOError);
63 result += int(c) - zeroOffset;
67 result += toupper(c) - alphaOffset;
75 // ************************************************************************* //