Update Turkish translation
[dasher.git] / Src / MacOSX / DasherUtil.mm
blob8eeb3c023ba092f7793bec0efe71729dab3607aa
1 //
2 //  DasherUtil.mm
3 //  Dasher
4 //
5 //  Created by Doug Dickinson on Sun Jun 01 2003.
6 //  Copyright (c) 2003 Doug Dickinson (dasher AT DressTheMonkey DOT plus DOT com). All rights reserved.
7 //
9 #import "DasherUtil.h"
10 #import <Cocoa/Cocoa.h>
11 #include <sys/time.h>
13 unsigned long get_time() {
14     // We need to provide a monotonic time source that ticks every millisecond
15   long s_now;
16   long ms_now;
17   
18   struct timeval tv;
19   
20   gettimeofday(&tv, NULL);
21   
22   s_now = tv.tv_sec;
23   ms_now = tv.tv_usec / 1000;
24   
25   unsigned long result = ((((unsigned long)s_now) & 0x0000ffff) * 1000UL) + ms_now;
26   return result;
31 NSString *NSStringFromStdString(const std::string& aString)
33   // inside DasherCore, std::string is used as a container for a string of UTF-8 bytes, so
34   // we can just get the raw bytes (with c_str()) and shove them into an NSString.
35   return [NSString stringWithUTF8String:aString.c_str()];
38 std::string StdStringFromNSString(NSString *aString)
40   std::string result;
42   if (aString && [aString length]) {
43     result = std::string([aString UTF8String]);
44   } else {
45     result = std::string("");
46   }
48   return result;