00001 // Filename: httpEntityTag.cxx 00002 // Created by: drose (28Jan03) 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 "httpEntityTag.h" 00020 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: HTTPEntityTag::Constructor 00024 // Access: Published 00025 // Description: This constructor accepts a string as formatted from 00026 // an HTTP server (e.g. the tag is quoted, with an 00027 // optional W/ prefix.) 00028 //////////////////////////////////////////////////////////////////// 00029 HTTPEntityTag:: 00030 HTTPEntityTag(const string &text) { 00031 _weak = false; 00032 00033 size_t p = 0; 00034 if (text.length() >= 2) { 00035 string sub = text.substr(0, 2); 00036 if (sub == "W/" || sub == "w/") { 00037 _weak = true; 00038 p = 2; 00039 } 00040 } 00041 00042 // Unquote the string. 00043 bool quoted = false; 00044 if (p < text.length() && text[p] == '"') { 00045 quoted = true; 00046 p++; 00047 } 00048 while (p < text.length() && !(quoted && text[p] == '"')) { 00049 if (text[p] == '\\') { 00050 p++; 00051 } 00052 _tag += text[p]; 00053 p++; 00054 } 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: HTTPEntityTag::get_string 00059 // Access: Published 00060 // Description: Returns the entity tag formatted for sending to an 00061 // HTTP server (the tag is quoted, with a conditional W/ 00062 // prefix). 00063 //////////////////////////////////////////////////////////////////// 00064 string HTTPEntityTag:: 00065 get_string() const { 00066 ostringstream result; 00067 if (_weak) { 00068 result << "W/"; 00069 } 00070 result << '"'; 00071 00072 for (string::const_iterator ti = _tag.begin(); ti != _tag.end(); ++ti) { 00073 switch (*ti) { 00074 case '"': 00075 case '\\': 00076 result << '\\'; 00077 // fall through 00078 00079 default: 00080 result << (*ti); 00081 } 00082 } 00083 00084 result << '"'; 00085 00086 return result.str(); 00087 }