Subversion Repositories php_utils

Rev

Rev 24 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24 Rev 86
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OID-Utilities for PHP
4
 * OID-Utilities for PHP
5
 * Copyright 2011-2022 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2011 - 2023 Daniel Marschall, ViaThinkSoft
6
 * Version 2022-01-07
6
 * Version 2023-08-25
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 224... Line 224...
224
 * @param   string $oid An OID in dot notation (with or without leading dot)
224
 * @param   string $oid An OID in dot notation (with or without leading dot)
225
 * @return  int The depth of the OID, e.g. 2.999 and .2.999 has the length 2.
225
 * @return  int The depth of the OID, e.g. 2.999 and .2.999 has the length 2.
226
 **/
226
 **/
227
function oid_len($oid) {
227
function oid_len($oid) {
228
        if ($oid == '') return 0;
228
        if ($oid == '') return 0;
229
        if ($oid[0] == '.') $oid = substr($oid, 1);
229
        if (substr($oid,0,1) == '.') $oid = substr($oid, 1);
230
        return substr_count($oid, '.')+1;
230
        return substr_count($oid, '.')+1;
231
}
231
}
232
function oid_depth($oid) {
232
function oid_depth($oid) {
233
        return oid_len($oid);
233
        return oid_len($oid);
234
}
234
}
Line 458... Line 458...
458
 **/
458
 **/
459
function oid_add_leading_dot($oid) {
459
function oid_add_leading_dot($oid) {
460
        $oid = sanitizeOID($oid, 'auto');
460
        $oid = sanitizeOID($oid, 'auto');
461
        if ($oid === false) return false;
461
        if ($oid === false) return false;
462
 
462
 
463
        if ($oid[0] != '.') $oid = '.'.$oid;
463
        if (substr($oid,0,1) != '.') $oid = '.'.$oid;
464
        return $oid;
464
        return $oid;
465
}
465
}
466
 
466
 
467
/**
467
/**
468
 * Removes a leading dot to an OID.
468
 * Removes a leading dot to an OID.