KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.5KB

  1. /* This file is part of the KDE project
  2. Copyright 2004 Tomas Mecir <mecirt@gmail.com>
  3. Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef KSPREAD_VALUEPARSER
  18. #define KSPREAD_VALUEPARSER
  19. #include <tqdatetime.h>
  20. #include "kspread_global.h"
  21. class KLocale;
  22. namespace KSpread
  23. {
  24. class Cell;
  25. class Value;
  26. /**
  27. The ValueParser parses a text input from the user, generating
  28. Value in the desired format.
  29. */
  30. class ValueParser {
  31. public:
  32. /** constructor */
  33. ValueParser (KLocale *locale);
  34. KLocale* locale();
  35. /** try to parse the text in a given cell and set value accordingly */
  36. void parse (const TQString& str, Cell *cell);
  37. /** try to parse given text, don't set any cell attributes though */
  38. Value parse (const TQString &str);
  39. Value tryParseBool (const TQString& str, bool *ok = 0);
  40. Value tryParseNumber (const TQString& str, bool *ok = 0);
  41. Value tryParseDate (const TQString& str, bool *ok = 0);
  42. Value tryParseTime (const TQString& str, bool *ok = 0);
  43. protected:
  44. KLocale* parserLocale;
  45. // Try to parse the text as a bool/number/date/time/etc.
  46. // Helpers for parse.
  47. bool tryParseBool (const TQString& str, Cell *cell);
  48. bool tryParseNumber (const TQString& str, Cell *cell);
  49. bool tryParseDate (const TQString& str, Cell *cell);
  50. bool tryParseTime (const TQString& str, Cell *cell);
  51. /** converts a string to a date/time value */
  52. TQDateTime readTime (const TQString & intstr, bool withSeconds, bool *ok,
  53. bool & duration);
  54. /** a helper function to read numbers and distinguish integers and FPs */
  55. double readNumber(const TQString &_str, bool * ok, bool * isInt);
  56. /** a helper function to read integers */
  57. int readInt (const TQString &str, uint &pos);
  58. FormatType fmtType;
  59. };
  60. } //namespace KSpread
  61. #endif //KSPREAD_VALUEPARSER