public static String makeValidNetcdfObjectName ( String name ) { StringBuilder sb = new StringBuilder ( name ) ; while ( sb . length ( ) > 0 ) { int cp = sb . codePointAt ( 0 ) ; // First char must be [a-z][A-Z][0-9]_ | UTF8 if ( cp <= 0x7f ) { if ( ! ( ' ' <= cp && cp <= ' ' ) && ! ( ' ' <= cp && cp <= ' ' ) && ! ( ' ' <= cp && cp <= ' ' ) && cp != ' ' ) { sb . deleteCharAt ( 0 ) ; continue ; } } break ; } for ( int pos = 1 ; pos < sb . length ( ) ; ++ pos ) { int cp = sb . codePointAt ( pos ) ; // handle simple 0x00-0x7F characters here if ( cp <= 0x7F ) { if ( cp < ' ' || cp > 0x7E || cp == ' ' ) { // control char, DEL, or forward-slash sb . deleteCharAt ( pos ) ; -- pos ; } } } while ( sb . length ( ) > 0 ) { int cp = sb . codePointAt ( sb . length ( ) - 1 ) ; if ( cp <= 0x7f && Character . isWhitespace ( cp ) ) { sb . deleteCharAt ( sb . length ( ) - 1 ) ; } else { break ; } } if ( sb . length ( ) == 0 ) { throw new IllegalArgumentException ( String . format ( "Illegal NetCDF object name: '%s'" , name ) ) ; } return sb . toString ( ) ; }
Convert a name to a legal netcdf - 3 name .