aboutsummaryrefslogtreecommitdiff
path: root/src/core/browser.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-13 04:50:49 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-13 04:50:49 +0800
commitd4f78be6f231b5289eb1c658d1f67006b7d884dd (patch)
tree8d27785fb97745f231e9879eb9bff81e8c225f60 /src/core/browser.cc
parent8449f5fcefc5406f1666257bacb3bb1afda978e1 (diff)
downloadrwebbrowser-d4f78be6f231b5289eb1c658d1f67006b7d884dd.tar.gz
rwebbrowser-d4f78be6f231b5289eb1c658d1f67006b7d884dd.tar.xz
feat: move URL formatting to Browser class and update documentation
Diffstat (limited to 'src/core/browser.cc')
-rw-r--r--src/core/browser.cc50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/core/browser.cc b/src/core/browser.cc
index 571783a..c4dbb08 100644
--- a/src/core/browser.cc
+++ b/src/core/browser.cc
@@ -412,30 +412,6 @@ void draw_view( const tui::Terminal& terminal,
std::cout.flush();
}
-std::string format_url( std::string input )
-{
- if ( input.empty() ) {
- return input;
- }
-
- if ( input.starts_with( "http://" ) || input.starts_with( "https://" ) ) {
- return input;
- }
-
- const bool is_domain = input.contains( '.' ) && !input.contains( ' ' );
- if ( is_domain ) {
- input.insert( 0, "https://" );
- return input;
- }
-
- for ( char& ch : input ) {
- if ( ch == ' ' ) {
- ch = '+';
- }
- }
- return "https://lite.duckduckgo.com/lite/?q=" + input;
-}
-
std::string get_url_input( const tui::Terminal& terminal )
{
auto [width, height] = terminal.get_size();
@@ -468,7 +444,7 @@ std::string get_url_input( const tui::Terminal& terminal )
}
terminal.show_cursor( false );
- return format_url( std::move( input ) );
+ return Browser::format_url( std::move( input ) );
}
// std::string get_link_input( const tui::Terminal& terminal )
@@ -1003,6 +979,30 @@ std::vector<std::string> wrap_lines( const std::vector<std::string>& original_li
} // namespace
+std::string Browser::format_url( std::string input )
+{
+ if ( input.empty() ) {
+ return input;
+ }
+
+ if ( input.starts_with( "http://" ) || input.starts_with( "https://" ) ) {
+ return input;
+ }
+
+ const bool is_domain = input.contains( '.' ) && !input.contains( ' ' );
+ if ( is_domain ) {
+ input.insert( 0, "https://" );
+ return input;
+ }
+
+ for ( char& ch : input ) {
+ if ( ch == ' ' ) {
+ ch = '+';
+ }
+ }
+ return "https://lite.duckduckgo.com/lite/?q=" + input;
+}
+
std::string Browser::get_configured_homepage()
{
std::ifstream file( get_config_path( "config.txt" ) );