Package nom.tam.fits.utilities
Class FitsHeaderCardParser
- java.lang.Object
-
- nom.tam.fits.utilities.FitsHeaderCardParser
-
public final class FitsHeaderCardParser extends java.lang.Object
A helper utility class to parse header cards for there value (especially strings) and comments.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FitsHeaderCardParser.ParsedValue
value comment pair of the header card.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
KEYWORD_PATTERN
pattern to match FITS keywords, specially to parse hirarchical keywords.private static java.util.regex.Pattern
STRING_PATTERN
pattern to match a quoted string where 2 quotes are used to escape a single quote inside the string.
-
Constructor Summary
Constructors Modifier Constructor Description private
FitsHeaderCardParser()
utility class will not be instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
deleteQuotes(java.lang.String quotedString)
delete the start and trailing quote from the sting and replace all (escaped)double quotes with a single quote.private static java.lang.String
extractComment(java.lang.String stringCard, int startPosition)
get the not empty comment string from the end of the card.static java.lang.String
parseCardKey(java.lang.String card)
parse a fits keyword from a card and return it as a dot separated list.static FitsHeaderCardParser.ParsedValue
parseCardValue(java.lang.String card)
Parse the card for a value and comment.private static FitsHeaderCardParser.ParsedValue
parseStringValue(java.lang.String card)
lets see if there is a quoted sting in the card.
-
-
-
Field Detail
-
KEYWORD_PATTERN
private static final java.util.regex.Pattern KEYWORD_PATTERN
pattern to match FITS keywords, specially to parse hirarchical keywords.
-
STRING_PATTERN
private static final java.util.regex.Pattern STRING_PATTERN
pattern to match a quoted string where 2 quotes are used to escape a single quote inside the string. Attention this patern ist optimized as specified in http://www.perlmonks.org/?node_id=607740
-
-
Method Detail
-
deleteQuotes
private static java.lang.String deleteQuotes(java.lang.String quotedString)
delete the start and trailing quote from the sting and replace all (escaped)double quotes with a single quote. Then trim the trailing blanks.- Parameters:
quotedString
- the string to un-quote.- Returns:
- the unquoted string
-
extractComment
private static java.lang.String extractComment(java.lang.String stringCard, int startPosition)
get the not empty comment string from the end of the card. start scanning from the end of the value.- Parameters:
stringCard
- the string representing the cardstartPosition
- the start point for the scan- Returns:
- the not empty comment or null if no comment was found.
-
parseCardKey
public static java.lang.String parseCardKey(java.lang.String card)
parse a fits keyword from a card and return it as a dot separated list.- Parameters:
card
- the card to parse.- Returns:
- dot separated key list
-
parseCardValue
public static FitsHeaderCardParser.ParsedValue parseCardValue(java.lang.String card)
Parse the card for a value and comment. Quoted string values are unquoted and theFitsHeaderCardParser.ParsedValue.isString
specifies if the value was a quoted string. non quoted values are trimmed.- Parameters:
card
- the card to parse.- Returns:
- a parsed card or null if no value could be detected.
-
parseStringValue
private static FitsHeaderCardParser.ParsedValue parseStringValue(java.lang.String card)
lets see if there is a quoted sting in the card.- Parameters:
card
- the card string to parse.- Returns:
- the parsed value with the unquoted string or null if no quoted string was found.
-
-