Set URLSegment to be unique on write
179550
public function onBeforeWrite() {
        parent::onBeforeWrite();

        $defaults = $this->owner->config()->defaults;
        $URLSegment = $this->owner->URLSegment;
        // If there is no URLSegment set, generate one from Title
        if((!$URLSegment || $URLSegment == $defaults['URLSegment']) && $this->owner->Title != $defaults['Title']) {
            $URLSegment = $this->generateURLSegment($this->owner->Title);
        } else if($this->owner->isChanged('URLSegment')) {
            // Make sure the URLSegment is valid for use in a URL
            $segment = preg_replace('/[^A-Za-z0-9]+/','-',$this->owner->URLSegment);
            $segment = preg_replace('/-+/','-',$segment);
            // If after sanitising there is no URLSegment, give it a reasonable default
            if(!$segment) {
                $segment = $this->fallbackUrl();
            }
            $URLSegment = $segment;
        }
        // Ensure that this object has a non-conflicting URLSegment value.
        $count = 2;
        $ID = $this->owner->ID;
        while($this->lookForExistingURLSegment($URLSegment, $ID)) {
            $URLSegment = preg_replace('/-[0-9]+$/', null, $URLSegment) . '-' . $count;
            $count++;
        }

        $this->owner->URLSegment = $URLSegment;
    }
1178705
def write_size (self, url_data):
        """"""
        self.writeln(u"<tr><td>"+self.part("dlsize")+u"</td><td>"+
                     strformat.strsize(url_data.size)+
                     u"</td></tr>")
977196
def write(url, object_, **args):
    """"""
    default_content_type = ('text/plain', {'charset': 'US-ASCII'})
    content_encoding = args.get('content_encoding', 'base64')
    content_type, params = args.get('content_type', default_content_type)
    data = content_types.get(content_type).format(object_, **params)
    args['data'].write('data:{}'.format(content_type))
    for param, value in params.items():
        args['data'].write(';{}={}'.format(param, value))
    if content_encoding == 'base64':
        args['data'].write(';base64,{}'.format(base64.b64decode(data)))
    else:
        args['data'].write(',{}', urllib.quote(data))
    args['data'].seek(0)
972822
def write_size (self, url_data):
        """"""
        self.write(self.part("dlsize") + self.spaces("dlsize"))
        self.writeln(strformat.strsize(url_data.size),
                     color=self.colordlsize)
648638
private void writeIlinkArgs(final PropertyWriter writer, final String linkID, final String[] args)
      throws SAXException {
    for (final String arg : args) {
      if (arg.charAt(0) == '/' || arg.charAt(0) == '-') {
        final int equalsPos = arg.indexOf('=');
        if (equalsPos > 0) {
          final String option = "option." + arg.substring(0, equalsPos - 1);
          writer.write(linkID, option + ".enabled", "1");
          writer.write(linkID, option + ".value", arg.substring(equalsPos + 1));
        } else {
          writer.write(linkID, "option." + arg.substring(1) + ".enabled", "1");
        }
      }
    }
  }
3644
private static String encodeUrlPart(final String part) throws UnsupportedEncodingException {
        //we need to go through and check part by part that a section does not need encoding

        int pos = 0;
        for (int i = 0; i < part.length(); ++i) {
            char c = part.charAt(i);
            if(c == '?') {
                break;
            } else if (c == '/') {
                if (pos != i) {
                    String original = part.substring(pos, i);
                    String encoded = URLEncoder.encode(original, UTF_8);
                    if (!encoded.equals(original)) {
                        return realEncode(part, pos);
                    }
                }
                pos = i + 1;
            } else if (c == ' ') {
                return realEncode(part, pos);
            }
        }
        return part;
    }
41396
function convertUrlSegmentToRegex(segment) {

    // if it has this format "{stuff}" - then it's regex-y
    var beginIdx = segment.indexOf('{');
    var endIdx = segment.indexOf('}');

    if (beginIdx < 0) {
        return segment;
    }

    // if capturing regex and trim trailing "}"
    // this could be a named regex {id:[0-9]+} or just name {companySlug}
    var pieces = segment.split(':');
    if (pieces.length === 2) {
        if ( pieces[1] === (urlPathPatternSymbol + '}') ) {
            // special case where we want to capture the whole remaining path, even slashes, like /search/a/b/c/
            return urlPathPattern;
        }
        else {
            return '(' + pieces[1].substring(0, pieces[1].length - 1) + ')';
        }
    }
    else if (pieces.length === 1) {
        return segment.substring(0, beginIdx) + '[^\\/]+' + segment.substring(endIdx + 1);
    }
    else {
        throw new Error('Weird URL segment- don\'t know how to parse! ' + segment);
    }
}
279948
function writeNode(state, level, object, block, compact, iskey) {
  state.tag = null;
  state.dump = object;

  if (!detectType(state, object, false)) {
    detectType(state, object, true);
  }

  var type = _toString.call(state.dump);

  if (block) {
    block = (state.flowLevel < 0 || state.flowLevel > level);
  }

  var objectOrArray = type === '[object Object]' || type === '[object Array]',
      duplicateIndex,
      duplicate;

  if (objectOrArray) {
    duplicateIndex = state.duplicates.indexOf(object);
    duplicate = duplicateIndex !== -1;
  }

  if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
    compact = false;
  }

  if (duplicate && state.usedDuplicates[duplicateIndex]) {
    state.dump = '*ref_' + duplicateIndex;
  } else {
    if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
      state.usedDuplicates[duplicateIndex] = true;
    }
    if (type === '[object Object]') {
      if (block && (Object.keys(state.dump).length !== 0)) {
        writeBlockMapping(state, level, state.dump, compact);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + state.dump;
        }
      } else {
        writeFlowMapping(state, level, state.dump);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
        }
      }
    } else if (type === '[object Array]') {
      var arrayLevel = (state.noArrayIndent && (level > 0)) ? level - 1 : level;
      if (block && (state.dump.length !== 0)) {
        writeBlockSequence(state, arrayLevel, state.dump, compact);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + state.dump;
        }
      } else {
        writeFlowSequence(state, arrayLevel, state.dump);
        if (duplicate) {
          state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
        }
      }
    } else if (type === '[object String]') {
      if (state.tag !== '?') {
        writeScalar(state, state.dump, level, iskey);
      }
    } else {
      if (state.skipInvalid) return false;
      throw new YAMLException('unacceptable kind of an object to dump ' + type);
    }

    if (state.tag !== null && state.tag !== '?') {
      state.dump = '!<' + state.tag + '> ' + state.dump;
    }
  }

  return true;
}
163597
def _build_url_rewriter(cls, session: AppSession):
        ''''''
        if session.args.escaped_fragment or session.args.strip_session_id:
            return session.factory.new(
                'URLRewriter',
                hash_fragment=session.args.escaped_fragment,
                session_id=session.args.strip_session_id
            )
885818
function addFragmentParam(url, param, value) {
  return url +
      (url.indexOf('#') == -1 ? '#' : '&') +
      encodeURIComponent(param) + '=' + encodeURIComponent(value);
}
1231079
private void encodePair(StringBuffer result, String name, Object value, boolean first) {
    if (!first)
      result.append('&');
    URLEncode(result, name);
    result.append('=');
    encodeObject(result, value);
  }
558051
static String encFragment(final String content, final Charset charset) {
		return urlencode(content, charset, FRAGMENT, false);
	}
810794
protected void fillDecoded(URLItem[] raw, String encoding, boolean scriptProteced, boolean sameAsArray) throws UnsupportedEncodingException {
	clear();
	String name, value;
	// Object curr;
	for (int i = 0; i < raw.length; i++) {
	    name = raw[i].getName();
	    value = raw[i].getValue();
	    if (raw[i].isUrlEncoded()) {
		name = URLDecoder.decode(name, encoding, true);
		value = URLDecoder.decode(value, encoding, true);
	    }
	    // MUST valueStruct
	    if (name.indexOf('.') != -1) {

		StringList list = ListUtil.listToStringListRemoveEmpty(name, '.');
		if (list.size() > 0) {
		    Struct parent = this;
		    while (list.hasNextNext()) {
			parent = _fill(parent, list.next(), new CastableStruct(Struct.TYPE_LINKED), false, scriptProteced, sameAsArray);
		    }
		    _fill(parent, list.next(), value, true, scriptProteced, sameAsArray);
		}
	    }
	    // else
	    _fill(this, name, value, true, scriptProteced, sameAsArray);
	}
    }
968676
function writeSubTable12(writer, segments) {

            writer.writeUint16(12); // format
            writer.writeUint16(0); // reserved
            writer.writeUint32(16 + segments.length * 12); // length
            writer.writeUint32(0); // language
            writer.writeUint32(segments.length); // nGroups

            segments.forEach(function (segment) {
                writer.writeUint32(segment.start);
                writer.writeUint32(segment.end);
                writer.writeUint32(segment.startId);
            });

            return writer;
        }
272563
private void processHyperlinkData(Resource resource, byte[] data)
   {
      if (data != null)
      {
         int offset = 12;
         String hyperlink;
         String address;
         String subaddress;

         offset += 12;
         hyperlink = MPPUtility.getUnicodeString(data, offset);
         offset += ((hyperlink.length() + 1) * 2);

         offset += 12;
         address = MPPUtility.getUnicodeString(data, offset);
         offset += ((address.length() + 1) * 2);

         offset += 12;
         subaddress = MPPUtility.getUnicodeString(data, offset);

         resource.setHyperlink(hyperlink);
         resource.setHyperlinkAddress(address);
         resource.setHyperlinkSubAddress(subaddress);
      }
   }
436426
JournalSegment<E> createSegment(JournalSegmentDescriptor descriptor) {
    File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());

    RandomAccessFile raf;
    FileChannel channel;
    try {
      raf = new RandomAccessFile(segmentFile, "rw");
      raf.setLength(descriptor.maxSegmentSize());
      channel =  raf.getChannel();
    } catch (IOException e) {
      throw new StorageException(e);
    }

    ByteBuffer buffer = ByteBuffer.allocate(JournalSegmentDescriptor.BYTES);
    descriptor.copyTo(buffer);
    buffer.flip();
    try {
      channel.write(buffer);
    } catch (IOException e) {
      throw new StorageException(e);
    } finally {
      try {
        channel.close();
        raf.close();
      } catch (IOException e) {
      }
    }
    JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
    log.debug("Created segment: {}", segment);
    return segment;
  }
1095770
def keepOriginalText(s,startLoc,t):
    """"""
    try:
        endloc = getTokensEndLoc()
    except ParseException:
        raise ParseFatalException("incorrect usage of keepOriginalText - may only be called as a parse action")
    del t[:]
    t += ParseResults(s[startLoc:endloc])
    return t