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