00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "pal_string_utils.h"
00016
00017 #include "pnmFileType.h"
00018 #include "pnmFileTypeRegistry.h"
00019
00020
00021
00022
00023 void
00024 extract_param_value(const string &str, string ¶m, string &value) {
00025 size_t i = 0;
00026
00027
00028 while (i < str.length() && isspace(str[i])) {
00029 i++;
00030 }
00031
00032 size_t start = i;
00033
00034
00035 while (i < str.length() && !isspace(str[i])) {
00036 i++;
00037 }
00038
00039 size_t end = i;
00040
00041 param = str.substr(start, end - start);
00042
00043
00044 while (i < str.length() && isspace(str[i])) {
00045 i++;
00046 }
00047 value = trim_right(str.substr(i));
00048 }
00049
00050
00051 bool
00052 parse_image_type_request(const string &word, PNMFileType *&color_type,
00053 PNMFileType *&alpha_type) {
00054 PNMFileTypeRegistry *registry = PNMFileTypeRegistry::get_global_ptr();
00055 color_type = (PNMFileType *)NULL;
00056 alpha_type = (PNMFileType *)NULL;
00057
00058 string color_name = word;
00059 string alpha_name;
00060 size_t comma = word.find(',');
00061 if (comma != string::npos) {
00062
00063
00064 color_name = word.substr(0, comma);
00065 alpha_name = word.substr(comma + 1);
00066 }
00067
00068 if (!color_name.empty()) {
00069 color_type = registry->get_type_from_extension(color_name);
00070 if (color_type == (PNMFileType *)NULL) {
00071 nout << "Image file type '" << color_name << "' is unknown.\n";
00072 return false;
00073 }
00074 }
00075
00076 if (!alpha_name.empty()) {
00077 alpha_type = registry->get_type_from_extension(alpha_name);
00078 if (alpha_type == (PNMFileType *)NULL) {
00079 nout << "Image file type '" << alpha_name << "' is unknown.\n";
00080 return false;
00081 }
00082 }
00083
00084 return true;
00085 }
00086
00087