bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_uri.cxx
blob592977ea03eeafb5ef8505bbab3196fd7ddd4a6d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /**************************************************************************
22 TODO
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
39 // Already inited?
40 if ( m_eState != UNKNOWN )
41 return;
43 m_eState = INVALID;
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).
49 return;
52 // Check for proper scheme. (Scheme is case insensitive.)
53 OUString aScheme
54 = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
55 if ( aScheme != TDOC_URL_SCHEME )
57 // Invalid scheme.
58 return;
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>).
67 return;
70 if ( m_aUri[ TDOC_URL_SCHEME_LENGTH + 1 ] != '/' )
72 // Invalid (no '/' after <scheme>:).
73 return;
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 );
92 if ( bTrailingSlash )
93 m_aName = m_aUri.copy( nLastSlash + 1,
94 m_aUri.getLength() - nLastSlash - 2 );
95 else
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 );
101 if ( nSlash == -1 )
102 m_aDocId = m_aPath.copy( 1 );
103 else
104 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
107 m_eState = VALID;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */