Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /url /url_parse_internal.h
blob: efae3640251d5fa65bc0b18dc580c6bdb08f8843 [file] [log] [blame] [edit]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/350788890): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif
#ifndef URL_URL_PARSE_INTERNAL_H_
#define URL_URL_PARSE_INTERNAL_H_
// Contains common inline helper functions used by the URL parsing routines.
#include"url/third_party/mozilla/url_parse.h"
namespace url{
// A helper function to handle a URL separator, which is '/' or '\'.
//
// The motivation: There are many condition checks in URL Standard like the
// following:
//
// > If url is special and c is U+002F (/) or U+005C (\), ...
inlineboolIsSlashOrBackslash(char16_t ch){
return ch=='/'|| ch=='\\';
}
inlineboolIsSlashOrBackslash(char ch){
returnIsSlashOrBackslash(static_cast<char16_t>(ch));
}
// Returns true if we should trim this character from the URL because it is a
// space or a control character.
inlineboolShouldTrimFromURL(char16_t ch){
return ch<=' ';
}
inlineboolShouldTrimFromURL(char ch){
returnShouldTrimFromURL(static_cast<char16_t>(ch));
}
// Given an already-initialized begin index and length, this shrinks the range
// to eliminate "should-be-trimmed" characters. Note that the length does *not*
// indicate the length of untrimmed data from |*begin|, but rather the position
// in the input string (so the string starts at character |*begin| in the spec,
// and goes until |*len|).
template<typename CHAR>
inlinevoidTrimURL(const CHAR* spec,int*begin,int* len,
bool trim_path_end=true){
// Strip leading whitespace and control characters.
while(*begin<*len&&ShouldTrimFromURL(spec[*begin]))
(*begin)++;
if(trim_path_end){
// Strip trailing whitespace and control characters. We need the >i test
// for when the input string is all blanks; we don't want to back past the
// input.
while(*len>*begin&&ShouldTrimFromURL(spec[*len-1]))
(*len)--;
}
}
// Counts the number of consecutive slashes or backslashes starting at the given
// offset in the given string of the given length. A slash and backslash can be
// mixed.
//
// TODO(crbug.com/40063064): Rename this function to
// `CountConsecutiveSlashesOrBackslashes`.
template<typename CHAR>
inlineintCountConsecutiveSlashes(const CHAR* str,
int begin_offset,
int str_len){
int count=0;
while(begin_offset+ count< str_len&&
IsSlashOrBackslash(str[begin_offset+ count])){
++count;
}
return count;
}
// Returns true if char is a slash.
inlineboolIsSlash(char16_t ch){
return ch=='/';
}
inlineboolIsSlash(char ch){
returnIsSlash(static_cast<char16_t>(ch));
}
// Counts the number of consecutive slashes starting at the given offset
// in the given string of the given length.
//
// TODO(crbug.com/40063064): Rename this function to
// `CountConsecutiveSlashes` after the current `CountConsecutiveSlashes` is
// renamed to CountConsecutiveSlashesOrBackslashes`.
template<typename CHAR>
inlineintCountConsecutiveSlashesButNotCountBackslashes(const CHAR* str,
int begin_offset,
int str_len){
int count=0;
while(begin_offset+ count< str_len&&IsSlash(str[begin_offset+ count])){
++count;
}
return count;
}
// Internal functions in url_parse.cc that parse the path, that is, everything
// following the authority section. The input is the range of everything
// following the authority section, and the output is the identified ranges.
//
// This is designed for the file URL parser or other consumers who may do
// special stuff at the beginning, but want regular path parsing, it just
// maps to the internal parsing function for paths.
voidParsePathInternal(constchar* spec,
constComponent& path,
Component* filepath,
Component* query,
Component*ref);
voidParsePathInternal(constchar16_t* spec,
constComponent& path,
Component* filepath,
Component* query,
Component*ref);
// Internal functions in url_parse.cc that parse non-special URLs, which are
// similar to `ParseNonSpecialURL` functions in url_parse.h, but with
// `trim_path_end` parameter that controls whether to trim path end or not.
ParsedParseNonSpecialURLInternal(std::string_view url,bool trim_path_end);
ParsedParseNonSpecialURLInternal(std::u16string_view url,bool trim_path_end);
// Given a spec and a pointer to the character after the colon following the
// special scheme, this parses it and fills in the structure, Every item in the
// parsed structure is filled EXCEPT for the scheme, which is untouched.
voidParseAfterSpecialScheme(constchar* spec,
int spec_len,
int after_scheme,
Parsed* parsed);
voidParseAfterSpecialScheme(constchar16_t* spec,
int spec_len,
int after_scheme,
Parsed* parsed);
// Given a spec and a pointer to the character after the colon following the
// non-special scheme, this parses it and fills in the structure, Every item in
// the parsed structure is filled EXCEPT for the scheme, which is untouched.
voidParseAfterNonSpecialScheme(constchar* spec,
int spec_len,
int after_scheme,
Parsed* parsed);
voidParseAfterNonSpecialScheme(constchar16_t* spec,
int spec_len,
int after_scheme,
Parsed* parsed);
}// namespace url
#endif// URL_URL_PARSE_INTERNAL_H_

[8]ページ先頭

©2009-2025 Movatter.jp