[2944] | 1 | /* $Id: kHlpGetExt.c 3575 2007-09-02 20:05:39Z bird $ */
|
---|
| 2 | /** @file
|
---|
[3575] | 3 | * kHlpPath - kHlpGetExt and kHlpGetSuff.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-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 | *
|
---|
[3575] | 16 | * kStuff is distributed in the hope that it will be useful,
|
---|
[2944] | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
[3575] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | * Lesser General Public License for more details.
|
---|
[2944] | 20 | *
|
---|
[3575] | 21 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 22 | * License along with kStuff; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
[2944] | 24 | *
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | /*******************************************************************************
|
---|
| 28 | * Header Files *
|
---|
| 29 | *******************************************************************************/
|
---|
[3573] | 30 | #include <k/kHlpPath.h>
|
---|
| 31 | #include <k/kHlpString.h>
|
---|
[2944] | 32 |
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Gets the filename suffix.
|
---|
| 36 | *
|
---|
| 37 | * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
|
---|
| 38 | * @returns Pointer to the terminator char if no suffix.
|
---|
| 39 | * @param pszFilename The filename to parse.
|
---|
| 40 | */
|
---|
[3575] | 41 | KHLP_DECL(char *) kHlpGetSuff(const char *pszFilename)
|
---|
[2944] | 42 | {
|
---|
| 43 | const char *pszDot = NULL;
|
---|
[3573] | 44 | pszFilename = kHlpGetFilename(pszFilename);
|
---|
[2944] | 45 | for (;;)
|
---|
| 46 | {
|
---|
| 47 | char ch = *pszFilename;
|
---|
| 48 | if (ch == '.')
|
---|
| 49 | {
|
---|
| 50 | while ((ch = *++pszFilename) == '.')
|
---|
| 51 | /* nothing */;
|
---|
| 52 | if (ch)
|
---|
| 53 | pszDot = pszFilename - 1;
|
---|
| 54 | }
|
---|
| 55 | if (!ch)
|
---|
| 56 | return (char *)(pszDot ? pszDot : pszFilename);
|
---|
| 57 | pszFilename++;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Gets the filename extention.
|
---|
| 64 | *
|
---|
| 65 | * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
|
---|
| 66 | * @returns Pointer to the terminator char if no extension.
|
---|
| 67 | * @param pszFilename The filename to parse.
|
---|
| 68 | */
|
---|
[3575] | 69 | KHLP_DECL(char *) kHlpGetExt(const char *pszFilename)
|
---|
[2944] | 70 | {
|
---|
[3573] | 71 | char *psz = kHlpGetSuff(pszFilename);
|
---|
[2944] | 72 | return *psz ? psz + 1 : psz;
|
---|
| 73 | }
|
---|
| 74 |
|
---|