To comment on the following update, log in, then open the issue:
http://www.openoffice.org/issues/show_bug.cgi?id=18134





------- Additional comments from [EMAIL PROTECTED] Sat Apr 30 10:48:33 -0700 
2005 -------
I would like an 'IP Address' number format.  This can be stored internally as a
regular number (as I believe dates are) but displayed and entered as an ip
address (10.1.1.45)

Here is some sample C++ that does the conversions

#include <iostream>
#include <string>
using namespace std;

int main()
{

   unsigned long number = 0;
   int tmp = 0, dots = 0;
   string ip;

/*  Parse IP Address
 *  Algorithm summary:
 *  
 *  Browse over each character in the input.
 *  Build a number until a dot is encountered or the number goes out of range.
 *  Repeat until end of string
 *  If an invalid character is found, bail out.
 */
   cin >> ip;
   for (int i = 0, j = ip.length(); i < j; i++)
   {
//      cout << i << ": " << ip[i] << endl;
      if (ip[i] >= '0' && ip[i] <= '9')
      {
         tmp = tmp * 10 + (ip[i] - '0');
         if (tmp > 255)
         {
            cout << "parse error: value out of range\n";
            return 3;
         }
//         cout << "tmp: " << tmp << endl;
         continue;
      }
      if (ip[i] == '.')
      {
         number *= 256;
         number += tmp;
         tmp = 0;
         dots++;
//         cout << "number; " << number << endl;
         continue;
      }
      cout << "parse error on character " << i << "\n";
      return 1;
   }
   if (dots != 3)
   {
      cout << "parse error: incorrect format\n";
      return 2;
   }
   number *= 256;
   number += tmp;
   tmp = 0;
   cout << number << endl;

/*  Format IP Address
 *  Algorithm summary:
 *  
 *  Extract each portion of the number and display.
 *  
 *  I think there may be a better way to do this by shifting bits then mod 256
 */
//   cin >> number;
   tmp = (number - (number % 16777216)) / 16777216;
   cout << tmp << ".";
   number %= 16777216;
   tmp = (number - (number % 65536)) / 65536;
   cout << tmp << ".";
   number %= 65536;
   tmp = (number - (number % 256)) / 256;
   cout << tmp << ".";
   number %= 256;
   cout << number << endl;

   return 0;
}


I'm not sure if this is closely related enough to this issue or not.  Should I
file a new issue specific to ip addresses?

---------------------------------------------------------------------
Please do not reply to this automatically generated notification from
Issue Tracker. Please log onto the website and enter your comments.
http://qa.openoffice.org/issue_handling/project_issues.html#notification

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to