Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/ucb/source/ucp/tdoc/tdoc_uri.cxx
Line
Count
Source
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
31
using namespace tdoc_ucp;
32
33
34
// Uri Implementation.
35
36
37
void Uri::init() const
38
22.6k
{
39
    // Already inited?
40
22.6k
    if ( m_eState != UNKNOWN )
41
11.3k
        return;
42
43
11.3k
    m_eState = INVALID;
44
45
    // Check for proper length: must be at least length of <scheme>:/
46
11.3k
    if ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 )
47
0
    {
48
        // Invalid length (to short).
49
0
        return;
50
0
    }
51
52
    // Check for proper scheme. (Scheme is case insensitive.)
53
11.3k
    OUString aScheme
54
11.3k
        = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
55
11.3k
    if ( aScheme != TDOC_URL_SCHEME )
56
0
    {
57
        // Invalid scheme.
58
0
        return;
59
0
    }
60
61
    // Remember normalized scheme string.
62
11.3k
    m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
63
64
11.3k
    if ( m_aUri[ TDOC_URL_SCHEME_LENGTH ] != ':' )
65
0
    {
66
        // Invalid (no ':' after <scheme>).
67
0
        return;
68
0
    }
69
70
11.3k
    if ( m_aUri[ TDOC_URL_SCHEME_LENGTH + 1 ] != '/' )
71
0
    {
72
        // Invalid (no '/' after <scheme>:).
73
0
        return;
74
0
    }
75
76
11.3k
    m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
77
78
    // Note: There must be at least one slash; see above.
79
11.3k
    sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
80
11.3k
    bool bTrailingSlash = false;
81
11.3k
    if ( nLastSlash == m_aUri.getLength() - 1 )
82
0
    {
83
        // ignore trailing slash
84
0
        bTrailingSlash = true;
85
0
        nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
86
0
    }
87
88
11.3k
    if ( nLastSlash != -1 ) // -1 is valid for the root folder
89
11.3k
    {
90
11.3k
        m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
91
92
11.3k
        if ( bTrailingSlash )
93
0
            m_aName = m_aUri.copy( nLastSlash + 1,
94
0
                                   m_aUri.getLength() - nLastSlash - 2 );
95
11.3k
        else
96
11.3k
            m_aName = m_aUri.copy( nLastSlash + 1 );
97
98
11.3k
        m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
99
100
11.3k
        sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
101
11.3k
        if ( nSlash == -1 )
102
11.3k
            m_aDocId = m_aPath.copy( 1 );
103
0
        else
104
0
            m_aDocId = m_aPath.copy( 1, nSlash - 1 );
105
11.3k
    }
106
107
11.3k
    m_eState = VALID;
108
109
11.3k
}
110
111
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */