<commit_before>/*
 * Created on 02-Feb-2006
 */
package uk.org.ponder.stringutil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.StringTokenizer;

import uk.org.ponder.util.Logger;
import uk.org.ponder.util.UniversalRuntimeException;

public class URLUtil {
  
  public static boolean isAbsolute(String url) {
    if (url.startsWith("javascript:") || url.startsWith("mailto:") || url.startsWith("file:")) 
        return true;
    int protpos = url.indexOf("://");
    if (protpos == -1) return false;
    for (int i = 0; i < protpos; ++ i) {
      if (!Character.isLetterOrDigit(url.charAt(i))) return false;
    }
    return true;
  }
  /** Append the supplied name/value pair to the end of the supplied URL, 
   * after URLencoding name and value.
   */
  
  public static String appendAttribute(String url, String name, String value) {
    int qpos = url.indexOf('?');
    char sep = qpos == -1? '?' : '&';
    return url + sep + URLEncoder.encode(name) + '=' + URLEncoder.encode(value);
  }
  
  /** Convert list of URL-form name/value pairs into a Map representation */
  // TODO: backport vector values code
  public static Map paramsToMap(String extraparams,
        Map target) {
      if (Logger.log.isDebugEnabled()) {
        Logger.log
          .debug("Action link requires extra parameters from " + extraparams);
      }
      StringTokenizer st = new StringTokenizer(extraparams, "&");
      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        int eqpos = token.indexOf("=");<commit_msg>Added appending name/value to URLUtil<commit_after>/*
 * Created on 02-Feb-2006
 */
package uk.org.ponder.stringutil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.StringTokenizer;

import uk.org.ponder.util.Logger;
import uk.org.ponder.util.UniversalRuntimeException;

/** Utilities for operating on URLs */

public class URLUtil {
  
  public static boolean isAbsolute(String url) {
    if (url.startsWith("javascript:") || url.startsWith("mailto:") || url.startsWith("file:")) 
        return true;
    int protpos = url.indexOf("://");
    if (protpos == -1) return false;
    for (int i = 0; i < protpos; ++ i) {
      if (!Character.isLetterOrDigit(url.charAt(i))) return false;
    }
    return true;
  }
  /** Append the supplied name/value pair to the end of the supplied URL, 
   * after URLencoding name and value.
   */
  
  public static String appendAttribute(String url, String name, String value) {
    CharWrap togo = new CharWrap(url);
    int qpos = url.indexOf('?');
    appendAttribute(togo, qpos == -1, name, value);
    return togo.toString();
  }

  /** Append the supplied name/value pair to the end of the supplied URL, 
   * after URLencoding name and value. The attribute will use the ? or &amp; 
   * character according to whether <code>isfirst</code> is true or false.
   */
  
  public static void appendAttribute(CharWrap togo, boolean isfirst, String name, String value) {
    togo.append(isfirst ? '?' : '&');
    togo.append(URLEncoder.encode(name));
    togo.append("=");
    togo.append(URLEncoder.encode(value));
  }
  
  /** Convert list of URL-form name/value pairs into a Map representation */
  // TODO: backport vector values code
  public static Map paramsToMap(String extraparams,
        Map target) {
      if (Logger.log.isDebugEnabled()) {
        Logger.log
          .debug("Action link requires extra parameters from " + extraparams);
      }
      StringTokenizer st = new StringTokenizer(extraparams, "&");
      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        int eqpos = token.indexOf("=");
{'fraction_non_alphanumeric': 0.12717536813922356, 'fraction_numerical': 0.004819277108433735, 'mean_word_length': 3.202474690663667, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6202453', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1131, 'n_words': 328}