Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/egg-palettize/pal_string_utils.cxx

Go to the documentation of this file.
00001 // Filename: pal_string_utils.cxx
00002 // Created by:  drose (30Nov00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "pal_string_utils.h"
00020 
00021 #include <pnmFileType.h>
00022 #include <pnmFileTypeRegistry.h>
00023 
00024 
00025 // Extracts the first word of the string into param, and the remainder
00026 // of the line into value.
00027 void
00028 extract_param_value(const string &str, string &param, string &value) {
00029   size_t i = 0;
00030 
00031   // First, skip all whitespace at the beginning.
00032   while (i < str.length() && isspace(str[i])) {
00033     i++;
00034   }
00035 
00036   size_t start = i;
00037 
00038   // Now skip to the end of the whitespace.
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   // Skip a little bit further to the start of the value.
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     // If we have a comma in the image_type, it's two types: a color
00067     // type and an alpha type.
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 

Generated on Fri May 2 03:17:42 2003 for Panda-Tool by doxygen1.3