/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/_str_helpers.pxd

s/follow_tree_references/recurse_nested/g

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007-2010 Canonical Ltd
 
2
# Copyright (C) 2018 Breezy developers
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
"""Trivial string helpers for use in other cython modules."""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
cdef extern from "python-compat.h":
 
23
    object PyBytes_FromStringAndSize (char *, Py_ssize_t)
 
24
    object PyBytes_InternFromStringAndSize (char *, Py_ssize_t)
 
25
 
 
26
 
 
27
cdef inline void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
 
28
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
 
29
    cdef char *pos
 
30
    cdef char *start
 
31
 
 
32
    start = <char*>s
 
33
    pos = start + n - 1
 
34
    while pos >= start:
 
35
        if pos[0] == c:
 
36
            return <void*>pos
 
37
        pos = pos - 1
 
38
    return NULL
 
39
 
 
40
 
 
41
cdef inline object safe_string_from_size(char *s, Py_ssize_t size):
 
42
    if size < 0:
 
43
        raise AssertionError(
 
44
            'tried to create a string with an invalid size: %d' % size)
 
45
    return PyBytes_FromStringAndSize(s, size)
 
46
 
 
47
 
 
48
cdef inline object safe_interned_string_from_size(char *s, Py_ssize_t size):
 
49
    if size < 0:
 
50
        raise AssertionError(
 
51
            'tried to create a string with an invalid size: %d' % size)
 
52
    return PyBytes_InternFromStringAndSize(s, size)