LibreOffice Module ucb (master) 1
tdoc_uri.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21/**************************************************************************
22 TODO
23 **************************************************************************
24
25 *************************************************************************/
26
27#include "../inc/urihelper.hxx"
28
29#include "tdoc_uri.hxx"
30
31using namespace tdoc_ucp;
32
33
34// Uri Implementation.
35
36
37void Uri::init() const
38{
39 // Already inited?
40 if ( m_eState != UNKNOWN )
41 return;
42
44
45 // Check for proper length: must be at least length of <scheme>:/
46 if ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 )
47 {
48 // Invalid length (to short).
49 return;
50 }
51
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 )
56 {
57 // Invalid scheme.
58 return;
59 }
60
61 // Remember normalized scheme string.
62 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
63
64 if ( m_aUri[ TDOC_URL_SCHEME_LENGTH ] != ':' )
65 {
66 // Invalid (no ':' after <scheme>).
67 return;
68 }
69
70 if ( m_aUri[ TDOC_URL_SCHEME_LENGTH + 1 ] != '/' )
71 {
72 // Invalid (no '/' after <scheme>:).
73 return;
74 }
75
77
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 )
82 {
83 // ignore trailing slash
84 bTrailingSlash = true;
85 nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
86 }
87
88 if ( nLastSlash != -1 ) // -1 is valid for the root folder
89 {
90 m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
91
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 );
97
99
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 );
105 }
106
107 m_eState = VALID;
108
109}
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
State m_eState
Definition: tdoc_uri.hxx:42
OUString m_aName
Definition: tdoc_uri.hxx:40
OUString m_aUri
Definition: tdoc_uri.hxx:36
OUString m_aParentUri
Definition: tdoc_uri.hxx:37
OUString m_aPath
Definition: tdoc_uri.hxx:38
OUString m_aDocId
Definition: tdoc_uri.hxx:39
OUString m_aDecodedName
Definition: tdoc_uri.hxx:41
OUString decodeSegment(const OUString &rSegment)
Definition: urihelper.hxx:37
#define TDOC_URL_SCHEME_LENGTH
Definition: tdoc_uri.hxx:29
#define TDOC_URL_SCHEME
Definition: tdoc_uri.hxx:28