<commit_before>#import "OpenGLView.h"
#import "InputDialog.h"
#include "FWContextBase.h"
#include "FWPlatformBase.h"

#include <ContextQuartz2D.h>
#include <CurlClient.h>

#import <Foundation/Foundation.h>

#include <iostream>

using namespace std;

namespace canvas {
class BundleFilenameConverter : public FilenameConverter {
public:
  bool convert(const std::string & input, std::string & output) {
    const char * filename = input.c_str();
    int n = (int)input.size();
    for (int i = n - 1; i >= 0; i--)  {
      if (filename[i] == '/')  {
        filename = filename + i + 1;
        break;
      }
    }
    // \Given a fileName, convert into a path that can be used to open from the mainBundle
    NSString* fileNameNS = [NSString stringWithUTF8String:filename];
    NSString* baseName = [fileNameNS stringByDeletingPathExtension];
    NSString* extension = [fileNameNS pathExtension];
    NSString *path = [[NSBundle mainBundle] pathForResource: baseName ofType: extension ];
    const char * filename2 = [path cStringUsingEncoding:1];
    if (filename2) {
      output = filename2;
      return true;
    } else {
      return false;
    }    
  }
};
};

class FWiOSPlatform : public FWPlatformBase {
public:
    FWiOSPlatform(OpenGLView * _controller, float _display_scale, const std::string & glsl_version, bool has_es3)
  : FWPlatformBase(_display_scale, glsl_version.c_str(), has_es3),
  controller(_controller) {
      defaults = [NSUserDefaults standardUserDefaults];
    }
    
    bool createWindow(FWContextBase * context, const char * title) {
        return true;
    }
    void createFBO(int flags) { 
      [controller createFBO: flags];
    }
    void showMessageBox(const std::string & message) {
      has_active_modal = true;
      has_active_modal = false;
    }
    void postNotification(const std::string & message) {
      NSString* message2 = [NSString stringWithUTF8String:message.c_str()];
//      [[NSNotificationCenter defaultCenter] postNotificationName:message2 object:self];
    }
    std::string showTextEntryDialog(const std::string & message) {
      // NSString* message2 = [NSString stringWithUTF8String:message];
      InputDialog * dlg = [InputDialog dialog];
      has_active_modal = true;
      [dlg showModal];
      has_active_modal = false;
      NSString * input = [dlg getInput];
      const char * stringAsChar = [input cStringUsingEncoding:NSUTF8StringEncoding];
      return stringAsChar;
    }
    std::string getBundleFilename(const char * filename) {
      int n = int(strlen(filename));
      for (int i = n - 1; i >= 0; i--)  {
        if (filename[i] == '/')  {
          filename = filename + i + 1;
          break;
        }
      }
      NSString* fileNameNS = [NSString stringWithUTF8String:filename];
      NSString* baseName = [fileNameNS stringByDeletingPathExtension];
      NSString* extension = [fileNameNS pathExtension];
      NSString *path = [[NSBundle mainBundle] pathForResource: baseName ofType: extension ];
      const char * filename2 = [path cStringUsingEncoding:1];
      // release stuff
      return filename2;
    }
   std::string getLocalFilename(const char * filename) {
      NSString* fileNameNS = [NSString stringWithUTF8String:filename];
      NSString *docsDir;
      NSArray *dirPaths;    
      // Get the documents directory
      dirPaths = NSSearchPathForDirectoriesInDomains
	(NSDocumentDirectory, NSUserDomainMask, YES);    
      docsDir = dirPaths[0];
      // Build the path to the database file
      NSString * finalPath = [[NSString alloc] initWithString: 
		      [docsDir stringByAppendingPathComponent: fileNameNS]];
    NSFileManager *filemgr = [NSFileManager defaultManager];
    std::string s([finalPath cStringUsingENcoding:1]);
    return s;
  }<commit_msg>fix initial implementation of getLocalFilename<commit_after>#import "OpenGLView.h"
#import "InputDialog.h"
#include "FWContextBase.h"
#include "FWPlatformBase.h"

#include <ContextQuartz2D.h>
#include <CurlClient.h>

#import <Foundation/Foundation.h>

#include <iostream>

using namespace std;

namespace canvas {
class BundleFilenameConverter : public FilenameConverter {
public:
  bool convert(const std::string & input, std::string & output) {
    const char * filename = input.c_str();
    int n = (int)input.size();
    for (int i = n - 1; i >= 0; i--)  {
      if (filename[i] == '/')  {
        filename = filename + i + 1;
        break;
      }
    }
    // \Given a fileName, convert into a path that can be used to open from the mainBundle
    NSString* fileNameNS = [NSString stringWithUTF8String:filename];
    NSString* baseName = [fileNameNS stringByDeletingPathExtension];
    NSString* extension = [fileNameNS pathExtension];
    NSString *path = [[NSBundle mainBundle] pathForResource: baseName ofType: extension ];
    const char * filename2 = [path cStringUsingEncoding:1];
    if (filename2) {
      output = filename2;
      return true;
    } else {
      return false;
    }    
  }
};
};

class FWiOSPlatform : public FWPlatformBase {
public:
    FWiOSPlatform(OpenGLView * _controller, float _display_scale, const std::string & glsl_version, bool has_es3)
  : FWPlatformBase(_display_scale, glsl_version.c_str(), has_es3),
  controller(_controller) {
      defaults = [NSUserDefaults standardUserDefaults];
    }
    
    bool createWindow(FWContextBase * context, const char * title) {
        return true;
    }
    void createFBO(int flags) { 
      [controller createFBO: flags];
    }
    void showMessageBox(const std::string & message) {
      has_active_modal = true;
      has_active_modal = false;
    }
    void postNotification(const std::string & message) {
      NSString* message2 = [NSString stringWithUTF8String:message.c_str()];
//      [[NSNotificationCenter defaultCenter] postNotificationName:message2 object:self];
    }
    std::string showTextEntryDialog(const std::string & message) {
      // NSString* message2 = [NSString stringWithUTF8String:message];
      InputDialog * dlg = [InputDialog dialog];
      has_active_modal = true;
      [dlg showModal];
      has_active_modal = false;
      NSString * input = [dlg getInput];
      const char * stringAsChar = [input cStringUsingEncoding:NSUTF8StringEncoding];
      return stringAsChar;
    }
    std::string getBundleFilename(const char * filename) {
      int n = int(strlen(filename));
      for (int i = n - 1; i >= 0; i--)  {
        if (filename[i] == '/')  {
          filename = filename + i + 1;
          break;
        }
      }
      NSString* fileNameNS = [NSString stringWithUTF8String:filename];
      NSString* baseName = [fileNameNS stringByDeletingPathExtension];
      NSString* extension = [fileNameNS pathExtension];
      NSString *path = [[NSBundle mainBundle] pathForResource: baseName ofType: extension ];
      const char * filename2 = [path cStringUsingEncoding:1];
      // release stuff
      return filename2;
    }
   std::string getLocalFilename(const char * filename) {
      NSString* fileNameNS = [NSString stringWithUTF8String:filename];
      NSString *docsDir;
      NSArray *dirPaths;    
      // Get the documents directory
      dirPaths = NSSearchPathForDirectoriesInDomains
	(NSDocumentDirectory, NSUserDomainMask, YES);    
      docsDir = dirPaths[0];
      // Build the path to the database file
      NSString * finalPath = [[NSString alloc] initWithString: 
		      [docsDir stringByAppendingPathComponent: fileNameNS]];
      const char * ptr = [finalPath cStringUsingEncoding:1];
     return ptr;
  }
{'fraction_non_alphanumeric': 0.10364963503649635, 'fraction_numerical': 0.007166556071665561, 'mean_word_length': 3.2793867120954006, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1267565', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2180, 'n_words': 574}