Panda3D
 All Classes Functions Variables Enumerations
pal_string_utils.cxx
1 // Filename: pal_string_utils.cxx
2 // Created by: drose (30Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pal_string_utils.h"
16 
17 #include "pnmFileType.h"
18 #include "pnmFileTypeRegistry.h"
19 
20 
21 // Extracts the first word of the string into param, and the remainder
22 // of the line into value.
23 void
24 extract_param_value(const string &str, string &param, string &value) {
25  size_t i = 0;
26 
27  // First, skip all whitespace at the beginning.
28  while (i < str.length() && isspace(str[i])) {
29  i++;
30  }
31 
32  size_t start = i;
33 
34  // Now skip to the end of the whitespace.
35  while (i < str.length() && !isspace(str[i])) {
36  i++;
37  }
38 
39  size_t end = i;
40 
41  param = str.substr(start, end - start);
42 
43  // Skip a little bit further to the start of the value.
44  while (i < str.length() && isspace(str[i])) {
45  i++;
46  }
47  value = trim_right(str.substr(i));
48 }
49 
50 
51 bool
52 parse_image_type_request(const string &word, PNMFileType *&color_type,
53  PNMFileType *&alpha_type) {
55  color_type = (PNMFileType *)NULL;
56  alpha_type = (PNMFileType *)NULL;
57 
58  string color_name = word;
59  string alpha_name;
60  size_t comma = word.find(',');
61  if (comma != string::npos) {
62  // If we have a comma in the image_type, it's two types: a color
63  // type and an alpha type.
64  color_name = word.substr(0, comma);
65  alpha_name = word.substr(comma + 1);
66  }
67 
68  if (!color_name.empty()) {
69  color_type = registry->get_type_from_extension(color_name);
70  if (color_type == (PNMFileType *)NULL) {
71  nout << "Image file type '" << color_name << "' is unknown.\n";
72  return false;
73  }
74  }
75 
76  if (!alpha_name.empty()) {
77  alpha_type = registry->get_type_from_extension(alpha_name);
78  if (alpha_type == (PNMFileType *)NULL) {
79  nout << "Image file type '" << alpha_name << "' is unknown.\n";
80  return false;
81  }
82  }
83 
84  return true;
85 }
86 
87 
PNMFileType * get_type_from_extension(const string &filename) const
Tries to determine what the PNMFileType is likely to be for a particular image file based on its exte...
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
This class maintains the set of all known PNMFileTypes in the universe.