1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /**************************************************************************
23 **************************************************************************
25 *************************************************************************/
27 #include "../inc/urihelper.hxx"
29 #include "tdoc_uri.hxx"
31 using namespace tdoc_ucp
;
34 // Uri Implementation.
37 void Uri::init() const
40 if ( m_eState
!= UNKNOWN
)
45 // Check for proper length: must be at least length of <scheme>:/
46 if ( m_aUri
.getLength() < TDOC_URL_SCHEME_LENGTH
+ 2 )
48 // Invalid length (to short).
52 // Check for proper scheme. (Scheme is case insensitive.)
54 = m_aUri
.copy( 0, TDOC_URL_SCHEME_LENGTH
).toAsciiLowerCase();
55 if ( aScheme
!= TDOC_URL_SCHEME
)
61 // Remember normalized scheme string.
62 m_aUri
= m_aUri
.replaceAt( 0, aScheme
.getLength(), aScheme
);
64 if ( m_aUri
[ TDOC_URL_SCHEME_LENGTH
] != ':' )
66 // Invalid (no ':' after <scheme>).
70 if ( m_aUri
[ TDOC_URL_SCHEME_LENGTH
+ 1 ] != '/' )
72 // Invalid (no '/' after <scheme>:).
76 m_aPath
= m_aUri
.copy( TDOC_URL_SCHEME_LENGTH
+ 1 );
78 // Note: There must be at least one slash; see above.
79 sal_Int32 nLastSlash
= m_aUri
.lastIndexOf( '/' );
80 bool bTrailingSlash
= false;
81 if ( nLastSlash
== m_aUri
.getLength() - 1 )
83 // ignore trailing slash
84 bTrailingSlash
= true;
85 nLastSlash
= m_aUri
.lastIndexOf( '/', nLastSlash
);
88 if ( nLastSlash
!= -1 ) // -1 is valid for the root folder
90 m_aParentUri
= m_aUri
.copy( 0, nLastSlash
+ 1 );
93 m_aName
= m_aUri
.copy( nLastSlash
+ 1,
94 m_aUri
.getLength() - nLastSlash
- 2 );
96 m_aName
= m_aUri
.copy( nLastSlash
+ 1 );
98 m_aDecodedName
= ::ucb_impl::urihelper::decodeSegment( m_aName
);
100 sal_Int32 nSlash
= m_aPath
.indexOf( '/', 1 );
102 m_aDocId
= m_aPath
.copy( 1 );
104 m_aDocId
= m_aPath
.copy( 1, nSlash
- 1 );
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */