| 562 | |
| 563 | #if EE_PLATFORM == EE_PLATFORM_WIN |
| 564 | void URI::parse( const std::string& _uri ) { |
| 565 | std::string uri( _uri ); |
| 566 | // Is a local path without hostname but it's correctly formatted? |
| 567 | if ( String::startsWith( uri, "file://" ) && uri.size() >= 9 ) { |
| 568 | if ( uri[7] != '/' && uri[8] == ':' ) { |
| 569 | uri[7] = std::tolower( uri[7] ); |
| 570 | uri.insert( uri.begin() + 7, '/' ); |
| 571 | } else if ( uri.size() >= 10 && uri[9] == ':' && uri[7] == '/' ) { |
| 572 | uri[8] = std::tolower( uri[8] ); |
| 573 | } |
| 574 | } |
| 575 | String::replaceAll( uri, "\\", "/" ); |
| 576 | #else |
| 577 | void URI::parse( const std::string& uri ) { |
| 578 | #endif |
| 579 | std::string::const_iterator it = uri.begin(); |
| 580 | std::string::const_iterator end = uri.end(); |
| 581 | if ( it == end ) |
| 582 | return; |
| 583 | if ( *it != '/' && *it != '.' && *it != '?' && *it != '#' ) { |
| 584 | std::string scheme; |
| 585 | while ( it != end && *it != ':' && *it != '?' && *it != '#' && *it != '/' ) |
| 586 | scheme += *it++; |
| 587 | if ( it != end && *it == ':' ) { |
| 588 | ++it; |
| 589 | if ( it == end ) { |
| 590 | return; // throw SyntaxException("URI scheme must be followed by authority or path", |
| 591 | // uri); |
| 592 | } |
| 593 | setScheme( scheme ); |
| 594 | if ( *it == '/' ) { |
| 595 | ++it; |
| 596 | if ( it != end && *it == '/' ) { |
| 597 | ++it; |
| 598 | parseAuthority( it, end ); |
| 599 | } else |
| 600 | --it; |
| 601 | } |
| 602 | parsePathEtc( it, end ); |
| 603 | } else { |
| 604 | it = uri.begin(); |
| 605 | parsePathEtc( it, end ); |
| 606 | } |
| 607 | } else { |
| 608 | parsePathEtc( it, end ); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | void URI::parseAuthority( std::string::const_iterator& it, |
| 613 | const std::string::const_iterator& end ) { |
| 614 | std::string userInfo; |
| 615 | std::string part; |
| 616 | while ( it != end && *it != '/' && *it != '?' && *it != '#' ) { |
| 617 | if ( *it == '@' ) { |
| 618 | userInfo = part; |
| 619 | part.clear(); |
| 620 | } else |
| 621 | part += *it; |
no test coverage detected