[2944] | 1 | /* $Id: kHlpGetExt.c 3608 2007-10-29 00:49:05Z bird $ */
|
---|
| 2 | /** @file
|
---|
[3575] | 3 | * kHlpPath - kHlpGetExt and kHlpGetSuff.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[3608] | 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
|
---|
[2944] | 8 | *
|
---|
[3575] | 9 | * This file is part of kStuff.
|
---|
[2944] | 10 | *
|
---|
[3575] | 11 | * kStuff is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 13 | * License as published by the Free Software Foundation; either
|
---|
| 14 | * version 2.1 of the License, or (at your option) any later version.
|
---|
[2944] | 15 | *
|
---|
[3608] | 16 | * In addition to the permissions in the GNU Lesser General Public
|
---|
| 17 | * License, you are granted unlimited permission to link the compiled
|
---|
| 18 | * version of this file into combinations with other programs, and to
|
---|
| 19 | * distribute those combinations without any restriction coming from
|
---|
| 20 | * the use of this file.
|
---|
| 21 | *
|
---|
[3575] | 22 | * kStuff is distributed in the hope that it will be useful,
|
---|
[2944] | 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
[3575] | 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 25 | * Lesser General Public License for more details.
|
---|
[2944] | 26 | *
|
---|
[3575] | 27 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 28 | * License along with kStuff; if not, write to the Free Software
|
---|
[3608] | 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
| 30 | * 02110-1301, USA
|
---|
[2944] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /*******************************************************************************
|
---|
| 34 | * Header Files *
|
---|
| 35 | *******************************************************************************/
|
---|
[3573] | 36 | #include <k/kHlpPath.h>
|
---|
| 37 | #include <k/kHlpString.h>
|
---|
[2944] | 38 |
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * Gets the filename suffix.
|
---|
| 42 | *
|
---|
| 43 | * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
|
---|
| 44 | * @returns Pointer to the terminator char if no suffix.
|
---|
| 45 | * @param pszFilename The filename to parse.
|
---|
| 46 | */
|
---|
[3575] | 47 | KHLP_DECL(char *) kHlpGetSuff(const char *pszFilename)
|
---|
[2944] | 48 | {
|
---|
| 49 | const char *pszDot = NULL;
|
---|
[3573] | 50 | pszFilename = kHlpGetFilename(pszFilename);
|
---|
[2944] | 51 | for (;;)
|
---|
| 52 | {
|
---|
| 53 | char ch = *pszFilename;
|
---|
| 54 | if (ch == '.')
|
---|
| 55 | {
|
---|
| 56 | while ((ch = *++pszFilename) == '.')
|
---|
| 57 | /* nothing */;
|
---|
| 58 | if (ch)
|
---|
| 59 | pszDot = pszFilename - 1;
|
---|
| 60 | }
|
---|
| 61 | if (!ch)
|
---|
| 62 | return (char *)(pszDot ? pszDot : pszFilename);
|
---|
| 63 | pszFilename++;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Gets the filename extention.
|
---|
| 70 | *
|
---|
| 71 | * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
|
---|
| 72 | * @returns Pointer to the terminator char if no extension.
|
---|
| 73 | * @param pszFilename The filename to parse.
|
---|
| 74 | */
|
---|
[3575] | 75 | KHLP_DECL(char *) kHlpGetExt(const char *pszFilename)
|
---|
[2944] | 76 | {
|
---|
[3573] | 77 | char *psz = kHlpGetSuff(pszFilename);
|
---|
[2944] | 78 | return *psz ? psz + 1 : psz;
|
---|
| 79 | }
|
---|
| 80 |
|
---|