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 "rtl/ustrbuf.hxx"
28 #include "../inc/urihelper.hxx"
30 #include "tdoc_uri.hxx"
32 using namespace tdoc_ucp
;
34 //=========================================================================
35 //=========================================================================
37 // Uri Implementation.
39 //=========================================================================
40 //=========================================================================
42 void Uri::init() const
45 if ( m_eState
== UNKNOWN
)
49 // Check for proper length: must be at least length of <sheme>:/
50 if ( ( m_aUri
.getLength() < TDOC_URL_SCHEME_LENGTH
+ 2 ) )
52 // Invaild length (to short).
56 // Check for proper scheme. (Scheme is case insensitive.)
58 = m_aUri
.copy( 0, TDOC_URL_SCHEME_LENGTH
).toAsciiLowerCase();
59 if ( aScheme
!= TDOC_URL_SCHEME
)
65 // Remember normalized scheme string.
66 m_aUri
= m_aUri
.replaceAt( 0, aScheme
.getLength(), aScheme
);
68 if ( m_aUri
.getStr()[ TDOC_URL_SCHEME_LENGTH
]
69 != sal_Unicode( ':' ) )
71 // Invaild (no ':' after <scheme>).
75 if ( m_aUri
.getStr()[ TDOC_URL_SCHEME_LENGTH
+ 1 ]
76 != sal_Unicode( '/' ) )
78 // Invaild (no '/' after <scheme>:).
82 m_aPath
= m_aUri
.copy( TDOC_URL_SCHEME_LENGTH
+ 1 );
84 // Note: There must be at least one slash; see above.
85 sal_Int32 nLastSlash
= m_aUri
.lastIndexOf( '/' );
86 bool bTrailingSlash
= false;
87 if ( nLastSlash
== m_aUri
.getLength() - 1 )
89 // ignore trailing slash
90 bTrailingSlash
= true;
91 nLastSlash
= m_aUri
.lastIndexOf( '/', nLastSlash
);
94 if ( nLastSlash
!= -1 ) // -1 is valid for the root folder
96 m_aParentUri
= m_aUri
.copy( 0, nLastSlash
+ 1 );
99 m_aName
= m_aUri
.copy( nLastSlash
+ 1,
100 m_aUri
.getLength() - nLastSlash
- 2 );
102 m_aName
= m_aUri
.copy( nLastSlash
+ 1 );
104 m_aDecodedName
= ::ucb_impl::urihelper::decodeSegment( m_aName
);
106 sal_Int32 nSlash
= m_aPath
.indexOf( '/', 1 );
108 m_aDocId
= m_aPath
.copy( 1 );
110 m_aDocId
= m_aPath
.copy( 1, nSlash
- 1 );
113 if ( !m_aDocId
.isEmpty() )
115 sal_Int32 nSlash
= m_aPath
.indexOf( '/', 1 );
117 m_aInternalPath
= m_aPath
.copy( nSlash
);
119 m_aInternalPath
= rtl::OUString("/");
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */