Example #1
0
func skipOrderedListMarker(s *StateBlock, startLine int) int {
	pos := s.BMarks[startLine] + s.TShift[startLine]
	max := s.EMarks[startLine]

	if pos+1 >= max {
		return -1
	}

	src := s.Src
	b := src[pos]

	if !byteutil.IsDigit(b) {
		return -1
	}

	start := pos

	for {
		if pos >= max {
			return -1
		}

		b = src[pos]
		pos++

		if byteutil.IsDigit(b) {
			if pos-start > 9 {
				return -1
			}
			continue
		}

		if afterdigit[b] {
			break
		}

		return -1
	}

	if pos < max && src[pos] != ' ' {
		return -1
	}

	return pos
}
Example #2
0
// Parse parses rawurl into a URL structure.
func Parse(rawurl string) (*URL, error) {
	n, err := findScheme(rawurl)
	if err != nil {
		return nil, err
	}

	var url URL
	rest := rawurl
	hostless := false
	if n > 0 {
		url.Scheme, rest = byteutil.ToLower(rest[:n]), rest[n+1:]
		if url.Scheme == "javascript" {
			hostless = true
		}
	}

	if !hostless && strings.HasPrefix(rest, "//") {
		url.Slashes, rest = true, rest[2:]
	}

	if !hostless && (url.Slashes || (url.Scheme != "" && !slashedProtocol[url.Scheme])) {
		hostEnd := byteutil.IndexAnyTable(rest, &cs2)
		atSign := -1
		i := hostEnd
		if i == -1 {
			i = len(rest) - 1
		}
		for i >= 0 {
			if rest[i] == '@' {
				atSign = i
				break
			}
			i--
		}

		if atSign != -1 {
			url.Auth, rest = rest[:atSign], rest[atSign+1:]
		}

		hostEnd = byteutil.IndexAnyTable(rest, &cs3)
		if hostEnd == -1 {
			hostEnd = len(rest)
		}
		if hostEnd > 0 && hostEnd < len(rest) && rest[hostEnd-1] == ':' {
			hostEnd--
		}
		host := rest[:hostEnd]

		if len(host) > 1 {
			b := host[hostEnd-1]
			if byteutil.IsDigit(b) {
				for i := len(host) - 2; i >= 0; i-- {
					b := host[i]
					if b == ':' {
						url.Host, url.Port = host[:i], host[i+1:]
						break
					}
					if !byteutil.IsDigit(b) {
						break
					}
				}
			} else if b == ':' {
				host = host[:hostEnd-1]
				hostEnd--
			}
		}
		if url.Port == "" {
			url.Host = host
		}
		rest = rest[hostEnd:]

		if ipv6 := len(url.Host) > 2 &&
			url.Host[0] == '[' &&
			url.Host[len(url.Host)-1] == ']'; ipv6 {
			url.Host = url.Host[1 : len(url.Host)-1]
			url.IPv6 = true
		} else if i := strings.IndexByte(url.Host, ':'); i >= 0 {
			url.Host, rest = url.Host[:i], url.Host[i:]+rest
		}
	}

	rest, url.Fragment = split(rest, '#')
	url.Path, url.RawQuery = split(rest, '?')

	return &url, nil
}