cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
elementnames.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 #include "cddefines.h"
4 #include "elementnames.h"
6 
7 /* nelem_symbol_to_index - obtain the array index the input element symbol refers to.
8  * The first letter is expected to be uppercase, and the second lowercase. */
9 int nelem_symbol_to_index( const char *chSym )
10 {
11  int ielem = -1;
12 
13  size_t symlen = strlen( chSym );
14  if( symlen == 0 || symlen >= size_t(CHARS_ELEMENT_SYM) )
15  return ielem;
16 
17  for( int i = 0; i < LIMELM; ++i )
18  {
19  if( symlen == 1 )
20  {
21  if( toupper( chSym[0] ) == elementnames.chElementSym[i][0] &&
22  elementnames.chElementSym[i][1] == ' ' )
23  {
24  ielem = i;
25  break;
26  }
27  }
28  else if( strncmp( elementnames.chElementSym[i], chSym, CHARS_ELEMENT_SYM ) == 0 )
29  {
30  ielem = i;
31  break;
32  }
33  }
34  return ielem;
35 }
36 
37 /* isElementSym - search for string among element symbols. */
38 bool isElementSym( const char *chSym )
39 {
40  return ( nelem_symbol_to_index( chSym ) != -1 ) ? true : false;
41 }
int nelem_symbol_to_index(const char *chSym)
Definition: elementnames.cpp:9
t_elementnames elementnames
Definition: elementnames.cpp:5
char toupper(char c)
Definition: cddefines.h:739
char chElementSym[LIMELM][CHARS_ELEMENT_SYM]
Definition: elementnames.h:25
const int LIMELM
Definition: cddefines.h:308
bool isElementSym(const char *chSym)