pike.git / lib / modules / Standards.pmod / URI.pike

version» Context lines:

pike.git/lib/modules/Standards.pmod/URI.pike:396:    authority = [string]value;    parse_authority(); // Set user, password, host and port accordingly    return value;       case "base_uri":    if(!stringp(value) && value!=0 && !objectp(value))    error("base_uri value neither object nor string.\n");    reparse_uri([object(this_program)|string]value);    return base_uri;    +  case "query": +  variables = 0; +  return ::`[]=(property, value); +     case "scheme":    /* RFC 3986 ยง3.1    *    * An implementation should accept uppercase letters as equivalent    * to lowercase in scheme names (e.g., allow "HTTP" as well as    * "http") for the sake of robustness but should only produce    * lowercase scheme names for consistency.    */    if(!stringp(value) && value!=0)    error("scheme value not string.\n");
pike.git/lib/modules/Standards.pmod/URI.pike:439:    return mkmapping(i, rows(this, i));    }   }      //! Returns path and query part of the URI if present.   string get_path_query()   {    return (path||"") + (query ? "?" + query : "");   }    + protected mapping(string:string) variables; +    //! Returns the query variables as a @expr{mapping(string:string)@}.   mapping(string:string) get_query_variables() { -  +  if( variables ) return variables;    if(!query) return ([]); -  return (mapping(string:string))((query/"&")[*]/"="); +  +  variables = ([]); +  foreach( query/"&";; string pair ) +  { +  if( sscanf( pair, "%s=%s", string var, string val )==2 ) +  variables[var] = val; +  else +  variables[pair] = 0;    }    -  +  return variables; + } +    //! Sets the query variables from the provided mapping.   void set_query_variables(mapping(string:string) vars) { -  +  variables = vars;    if(!sizeof(vars))    query = 0;    else -  query = ((array)vars)[*]*"="*"&"; +  { +  query = ""; +  foreach( vars; string var; string val ) +  { +  if( sizeof(query) ) +  query += "&"; +  query += var; +  if( val ) +  query += "=" + val;    } -  +  } + }      //! Adds the provided query variable to the already existing ones.   //! Will overwrite an existing variable with the same name.   void add_query_variable(string name, string value) {    set_query_variables(get_query_variables()+([name:value]));   }      //! Appends the provided set of query variables with the already   //! existing ones. Will overwrite all existing variables with the same   //! names.